Skip to content

Commit 1baa7f2

Browse files
authored
Merge pull request #628 from nateberkopec/version-header-fix
Fix Version header
2 parents b10311e + 884998d commit 1baa7f2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/raven/integrations/rack.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def format_headers_for_sentry(env_hash)
101101
# env['SERVER_PROTOCOL']. But we don't want to ignore a valid header
102102
# if the request has legitimately sent a Version header themselves.
103103
# See: https://github.com/rack/rack/blob/028438f/lib/rack/handler/cgi.rb#L29
104-
next if key == 'HTTP_VERSION' && value == ENV['SERVER_PROTOCOL']
104+
next if key == 'HTTP_VERSION' && value == env_hash['SERVER_PROTOCOL']
105105

106106
next unless key.start_with?('HTTP_') || %w(CONTENT_TYPE CONTENT_LENGTH).include?(key)
107107
# Rack stores headers as HTTP_WHAT_EVER, we need What-Ever

spec/raven/integrations/rack_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@
8484
stack.call(env)
8585
end
8686

87+
it 'transforms headers to conform with the interface' do
88+
env = { "SERVER_PROTOCOL" => "HTTP/1.1", "HTTP_FOO" => "BAR", "HTTP_VERSION" => "HTTP/1.1" }
89+
90+
interface = Raven::HttpInterface.new
91+
interface.from_rack(env)
92+
93+
expect(interface.headers["Foo"]).to eq("BAR")
94+
expect(interface.headers["Version"]).to be_nil
95+
end
96+
97+
it 'does not ignore version headers which do not match SERVER_PROTOCOL' do
98+
env = { "SERVER_PROTOCOL" => "HTTP/1.1", "HTTP_VERSION" => "HTTP/2.0" }
99+
100+
interface = Raven::HttpInterface.new
101+
interface.from_rack(env)
102+
103+
expect(interface.headers["Version"]).to eq("HTTP/2.0")
104+
end
105+
87106
it 'should pass rack/lint' do
88107
env = Rack::MockRequest.env_for("/test")
89108

0 commit comments

Comments
 (0)