Skip to content

Commit

Permalink
Retain any literal "HTTP-" in header names (#950)
Browse files Browse the repository at this point in the history
If a literal "HTTP-" exists in a request header name, it will appear as
"HTTP_" in the Rack environment. This shouldn't be removed when
extracting it from the environment.
  • Loading branch information
elliterate committed Mar 2, 2020
1 parent fa3aa4a commit 68e575e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/raven/integrations/rack.rb
Expand Up @@ -113,7 +113,7 @@ def format_headers_for_sentry(env_hash)

next unless key.start_with?('HTTP_') || %w(CONTENT_TYPE CONTENT_LENGTH).include?(key)
# Rack stores headers as HTTP_WHAT_EVER, we need What-Ever
key = key.gsub("HTTP_", "")
key = key.sub(/^HTTP_/, "")
key = key.split('_').map(&:capitalize).join('-')
memo[key] = value
rescue StandardError => e
Expand Down
8 changes: 8 additions & 0 deletions spec/raven/integrations/rack_spec.rb
Expand Up @@ -103,6 +103,14 @@
expect(interface.headers["Version"]).to eq("HTTP/2.0")
end

it 'retains any literal "HTTP-" in the actual header name' do
interface = Raven::HttpInterface.new
new_env = env.merge("HTTP_HTTP_CUSTOM_HTTP_HEADER" => "test")
interface.from_rack(new_env)

expect(interface.headers).to include("Http-Custom-Http-Header" => "test")
end

it 'does not fail if an object in the env cannot be cast to string' do
obj = Class.new do
def to_s
Expand Down

0 comments on commit 68e575e

Please sign in to comment.