1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Add redacted_uri, redacted_url methods.

These make it easier for callers to access the password-free versions of
the URI used by log_request.
This commit is contained in:
Andy Brody 2016-05-15 23:08:43 -04:00
parent a6d6eada70
commit 4584ae9f8a
2 changed files with 17 additions and 9 deletions

View file

@ -79,6 +79,8 @@ This release is largely API compatible, but makes several breaking changes.
- Add a few more exception classes for obscure HTTP status codes.
- Multipart: use a much more robust multipart boundary with greater entropy.
- Make `RestClient::Payload::Base#inspect` stop pretending to be a String.
- Add `Request#redacted_uri` and `Request#redacted_url` to display the URI
with any password redacted.
# 2.0.0.rc1

View file

@ -426,20 +426,26 @@ module RestClient
end
end
def redacted_uri
if uri.password
sanitized_uri = uri.dup
sanitized_uri.password = 'REDACTED'
sanitized_uri
else
uri
end
end
def redacted_url
redacted_uri.to_s
end
def log_request
return unless RestClient.log
if uri.password
sanitized_uri = uri.dup
sanitized_uri.password = "REDACTED"
sanitized_url = sanitized_uri.to_s
else
sanitized_url = uri.to_s
end
out = []
out << "RestClient.#{method} #{sanitized_url.inspect}"
out << "RestClient.#{method} #{redacted_url.inspect}"
out << payload.short_inspect if payload
out << processed_headers.to_a.sort.map { |(k, v)| [k.inspect, v.inspect].join("=>") }.join(", ")
RestClient.log << out.join(', ') + "\n"