From be88e829ba1cb997f7386bc9af6b41efd48d1144 Mon Sep 17 00:00:00 2001 From: Ian Lesperance Date: Thu, 23 Jan 2020 12:14:05 -0500 Subject: [PATCH] Retain any literal "HTTP-" in header names 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. --- lib/raven/integrations/rack.rb | 2 +- spec/raven/integrations/rack_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/raven/integrations/rack.rb b/lib/raven/integrations/rack.rb index 1bd780a26..6e8711676 100644 --- a/lib/raven/integrations/rack.rb +++ b/lib/raven/integrations/rack.rb @@ -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 diff --git a/spec/raven/integrations/rack_spec.rb b/spec/raven/integrations/rack_spec.rb index 8c1e1bc49..964835bb9 100644 --- a/spec/raven/integrations/rack_spec.rb +++ b/spec/raven/integrations/rack_spec.rb @@ -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