diff --git a/history.md b/history.md index 2a99e76..4a135bb 100644 --- a/history.md +++ b/history.md @@ -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 diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb index 98a9e82..f011c91 100644 --- a/lib/restclient/request.rb +++ b/lib/restclient/request.rb @@ -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"