Module: Datadog::Contrib::Sinatra::Headers

Defined in:
lib/ddtrace/contrib/sinatra/headers.rb

Overview

Gets and sets trace information from a Rack headers Hash

Class Method Summary collapse

Class Method Details

.response_header_tags(headers, target_headers) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ddtrace/contrib/sinatra/headers.rb', line 10

def response_header_tags(headers, target_headers)
  target_headers ||= []

  {}.tap do |result|
    target_headers.each do |header|
      if headers.key?(header)
        result[Datadog::Ext::HTTP::ResponseHeaders.to_tag(header)] = headers[header]
      else
        # Try a case-insensitive lookup
        uppercased_header = header.to_s.upcase
        matching_header = headers.keys.find { |h| h.upcase == uppercased_header }
        if matching_header
          result[Datadog::Ext::HTTP::ResponseHeaders.to_tag(header)] = headers[matching_header]
        end
      end
    end
  end
end