Skip to content
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

Add Content-Length and Content-Type headers to the reports #513

Merged
merged 1 commit into from
Sep 1, 2016
Merged
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
4 changes: 3 additions & 1 deletion lib/rollbar/request_data_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

module Rollbar
module RequestDataExtractor
ALLOWED_HEADERS_REGEX = /^HTTP_|^CONTENT_TYPE$|^CONTENT_LENGTH$/

def extract_person_data_from_controller(env)
if env.has_key?('rollbar.person_data')
person_data = env['rollbar.person_data'] || {}
Expand Down Expand Up @@ -92,7 +94,7 @@ def rollbar_request_method(env)
end

def rollbar_headers(env)
env.keys.grep(/^HTTP_/).map do |header|
env.keys.grep(ALLOWED_HEADERS_REGEX).map do |header|
name = header.gsub(/^HTTP_/, '').split('_').map(&:capitalize).join('-')
if name == 'Cookie'
{}
Expand Down
19 changes: 19 additions & 0 deletions spec/rollbar/request_data_extractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,25 @@ class ExtractorDummy

expect(result).to be_kind_of(Hash)
end

context 'with CONTENT_TYPE and CONTENT_LENGTH headers' do
let(:env) do
Rack::MockRequest.env_for('/',
'HTTP_HOST' => 'localhost:81',
'HTTP_X_FORWARDED_HOST' => 'example.org:9292',
'CONTENT_TYPE' => 'application/json',
'CONTENT_LENGTH' => 20)


end

it 'adds the content type header to the headers key' do
result = subject.extract_request_data_from_rack(env)

expect(result[:headers]['Content-Type']).to be_eql('application/json')
expect(result[:headers]['Content-Length']).to be_eql(20)
end
end
end
end
end