Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions lib/httplog/adapters/ethon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def httplog_add_callback
@on_complete.unshift -> (*) do
# Not sure where the actual status code is stored - so let's
# extract it from the response header.
encoding = response_headers.scan(/Content-Encoding: (\S+)/).flatten.first
content_type = response_headers.scan(/Content-Type: (\S+(; charset=\S+)?)/).flatten.first
encoding = response_headers.scan(/Content-Encoding: (\S+)/i).flatten.first
content_type = response_headers.scan(/Content-Type: (\S+(; charset=\S+)?)/i).flatten.first

# Hard to believe that Ethon wouldn't parse out the headers into
# an array; probably overlooked it. Anyway, let's do it ourselves:
Expand Down
7 changes: 4 additions & 3 deletions lib/httplog/adapters/httpclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def do_get_block(req, proxy, conn, &block)
request_uri = req.header.request_uri
if HttpLog.url_approved?(request_uri)
res = conn.pop
headers = res.headers.transform_keys { |key| key.downcase }

HttpLog.call(
method: req.header.request_method,
Expand All @@ -27,10 +28,10 @@ def do_get_block(req, proxy, conn, &block)
request_headers: req.headers,
response_code: res.status_code,
response_body: res.body,
response_headers: res.headers,
response_headers: headers,
benchmark: bm,
encoding: res.headers['Content-Encoding'],
content_type: res.headers['Content-Type'],
encoding: headers['content-encoding'],
content_type: headers['content-type'],
mask_body: HttpLog.masked_body_url?(request_uri)
)
conn.push(res)
Expand Down
8 changes: 5 additions & 3 deletions lib/httplog/adapters/patron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ def request(action_name, url, headers, options = {})
end

if HttpLog.url_approved?(url)
normalized_headers = @response.headers.transform_keys { |key| key.downcase }

HttpLog.call(
method: action_name,
url: url,
request_body: options[:data],
request_headers: headers,
response_code: @response.status,
response_body: @response.body,
response_headers: @response.headers,
response_headers: normalized_headers,
benchmark: bm,
encoding: @response.headers['Content-Encoding'],
content_type: @response.headers['Content-Type'],
encoding: normalized_headers['content-encoding'],
content_type: normalized_headers['content-type'],
mask_body: HttpLog.masked_body_url?(url)
)
end
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/http_log_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ def configure
expect(response_string).to eq(adapter.expected_full_response_body)
end

context 'with lowercase headers' do
let(:path) { '/index.html' }
let(:data) { 'downcase=true' }

it_behaves_like 'logs expected response'
end

context 'with gzip encoding' do
let(:path) { '/index.html.gz' }
let(:data) { nil }
Expand Down
3 changes: 3 additions & 0 deletions spec/support/test_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def call(env)
headers['Content-Type'] = 'text/html; charset=UTF-8' if path =~ /utf8/
headers['Content-Type'] = 'application/json' if path =~ /json/
headers['Content-Encoding'] = 'gzip' if File.extname(file) == '.gz'

headers.transform_keys! { |key| key.downcase } if params['downcase']

[200, headers, File.binread(file)]
else
[404, { 'Content-Type' => 'text/plain' }, 'file not found']
Expand Down