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:
parent
a6d6eada70
commit
4584ae9f8a
2 changed files with 17 additions and 9 deletions
|
@ -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.
|
- Add a few more exception classes for obscure HTTP status codes.
|
||||||
- Multipart: use a much more robust multipart boundary with greater entropy.
|
- Multipart: use a much more robust multipart boundary with greater entropy.
|
||||||
- Make `RestClient::Payload::Base#inspect` stop pretending to be a String.
|
- 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
|
# 2.0.0.rc1
|
||||||
|
|
||||||
|
|
|
@ -426,20 +426,26 @@ module RestClient
|
||||||
end
|
end
|
||||||
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
|
def log_request
|
||||||
return unless RestClient.log
|
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 = []
|
||||||
|
|
||||||
out << "RestClient.#{method} #{sanitized_url.inspect}"
|
out << "RestClient.#{method} #{redacted_url.inspect}"
|
||||||
out << payload.short_inspect if payload
|
out << payload.short_inspect if payload
|
||||||
out << processed_headers.to_a.sort.map { |(k, v)| [k.inspect, v.inspect].join("=>") }.join(", ")
|
out << processed_headers.to_a.sort.map { |(k, v)| [k.inspect, v.inspect].join("=>") }.join(", ")
|
||||||
RestClient.log << out.join(', ') + "\n"
|
RestClient.log << out.join(', ') + "\n"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue