Skip to content

Add option to not filter_authorization #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ HttpLogger.ignore = [/newrelic\.com/]
HttpLogger.log_headers = false # Default: false
HttpLogger.log_request_body = false # Default: true
HttpLogger.log_response_body = false # Default: true
HttpLogger.filter_authorization = false # Default: true
HttpLogger.level = :info # Desired log level as a symbol. Default: :debug
HttpLogger.collapse_body_limit # Change default truncate limit. Default: 5000
```
Expand Down
8 changes: 7 additions & 1 deletion lib/http_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class << self
attr_accessor :log_headers
attr_accessor :log_request_body
attr_accessor :log_response_body
attr_accessor :filter_authorization
attr_accessor :logger
attr_accessor :colorize
attr_accessor :ignore
Expand All @@ -38,6 +39,7 @@ class << self
self.log_headers = false
self.log_request_body = true
self.log_response_body = true
self.filter_authorization = true
self.colorize = true
self.collapse_body_limit = 5000
self.ignore = []
Expand Down Expand Up @@ -91,7 +93,11 @@ def log_request_headers(request)
end

def log_header(type, name, value)
value = "<filtered>" if name == AUTHORIZATION_HEADER
if name == AUTHORIZATION_HEADER
if self.class.filter_authorization
value = "<filtered>"
end
end
log("HTTP #{type} header", "#{name}: #{value}")
end

Expand Down
17 changes: 15 additions & 2 deletions spec/http_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,23 @@

context "authorization header" do

let(:bearer_token) { "Basic #{Base64.encode64('hello:world')}".strip }
let(:request_headers) do
{'Authorization' => "Basic #{Base64.encode64('hello:world')}".strip}
{'Authorization' => bearer_token}
end

context "filtered" do
it { should include("Authorization: <filtered>") }
end

context "not filtered" do

before(:each) do
HttpLogger.filter_authorization = false
end

it { should include("Authorization: #{bearer_token}") }
end
it { should include("Authorization: <filtered>") }
end

after(:each) do
Expand Down