Skip to content

Commit

Permalink
Fix cookies, put in correct spot. Fix #787 (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
nateberkopec committed Jan 28, 2018
1 parent 6d7b01b commit 9649fa5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/raven/integrations/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ def from_rack(env_hash)
self.method = req.request_method
self.query_string = req.query_string
self.data = read_data_from(req)
self.cookies = req.cookies

self.headers = format_headers_for_sentry(env_hash)
self.env = format_env_for_sentry(env_hash)
self.env = format_env_for_sentry(env_hash)
end

private
Expand Down Expand Up @@ -108,6 +109,7 @@ def format_headers_for_sentry(env_hash)
# if the request has legitimately sent a Version header themselves.
# See: https://github.com/rack/rack/blob/028438f/lib/rack/handler/cgi.rb#L29
next if key == 'HTTP_VERSION' && value == env_hash['SERVER_PROTOCOL']
next if key == 'HTTP_COOKIE' # Cookies don't go here, they go somewhere else

next unless key.start_with?('HTTP_') || %w(CONTENT_TYPE CONTENT_LENGTH).include?(key)
# Rack stores headers as HTTP_WHAT_EVER, we need What-Ever
Expand Down
2 changes: 1 addition & 1 deletion spec/raven/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
:method => 'POST',
:query_string => 'biz=baz',
:url => 'http:https://localhost/lol',
:cookies => nil)
:cookies => {})
end

it "sets user context ip address correctly" do
Expand Down
13 changes: 10 additions & 3 deletions spec/raven/integrations/rack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,18 @@

it 'transforms headers to conform with the interface' do
interface = Raven::HttpInterface.new
new_env = env.merge("HTTP_VERSION" => "HTTP/1.1")
new_env = env.merge("HTTP_VERSION" => "HTTP/1.1", "HTTP_COOKIE" => "test")
interface.from_rack(new_env)

expect(interface.headers["Content-Length"]).to eq("0")
expect(interface.headers["Version"]).to eq("HTTP/1.1")
expect(interface.headers).to eq("Content-Length" => "0", "Version" => "HTTP/1.1")
end

it 'puts cookies into the cookies attribute' do
interface = Raven::HttpInterface.new
new_env = env.merge("HTTP_COOKIE" => "test")
interface.from_rack(new_env)

expect(interface.cookies).to eq("test" => nil)
end

it 'does not ignore version headers which do not match SERVER_PROTOCOL' do
Expand Down

0 comments on commit 9649fa5

Please sign in to comment.