File tree 2 files changed +30
-1
lines changed
lib/datadog/tracing/contrib/rack
spec/datadog/tracing/contrib/rack
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,17 @@ def key?(header_name)
31
31
end
32
32
33
33
def self . to_rack_header ( name )
34
- "HTTP_#{ name . to_s . upcase . gsub ( /[-\s ]/ , '_' ) } "
34
+ key = name . to_s . upcase . gsub ( /[-\s ]/ , '_' )
35
+ case key
36
+ when 'CONTENT_TYPE' , 'CONTENT_LENGTH'
37
+ # NOTE: The Rack spec says:
38
+ # > The environment must not contain the keys HTTP_CONTENT_TYPE or HTTP_CONTENT_LENGTH
39
+ # > (use the versions without HTTP_).
40
+ # See https://github.com/rack/rack/blob/e217a399eb116362710aac7c5b8dc691ea2189b3/SPEC.rdoc?plain=1#L119-L121
41
+ key
42
+ else
43
+ "HTTP_#{ key } "
44
+ end
35
45
end
36
46
end
37
47
end
Original file line number Diff line number Diff line change 32
32
expect ( collection . get ( 'X-Forwarded-For' ) ) . to be_nil
33
33
end
34
34
end
35
+
36
+ context 'when Content-Type and Content-Length headers exist in env' do
37
+ let ( :env ) do
38
+ {
39
+ 'CONTENT_TYPE' => 'application/json' ,
40
+ 'CONTENT_LENGTH' => '120'
41
+ }
42
+ end
43
+
44
+ it 'returns header value' do
45
+ expect ( collection . get ( 'Content-Type' ) ) . to eq ( 'application/json' )
46
+ expect ( collection . get ( 'Content-Length' ) ) . to eq ( '120' )
47
+ end
48
+
49
+ it 'returns header value regardless of letter casing in the name' do
50
+ expect ( collection . get ( 'content-type' ) ) . to eq ( 'application/json' )
51
+ expect ( collection . get ( 'content-length' ) ) . to eq ( '120' )
52
+ end
53
+ end
35
54
end
36
55
end
You can’t perform that action at this time.
0 commit comments