Sha256: f33bfc4779ad97bf8334f7a03068cc15e6d2b7700516ebea1cbda4524ecb4b57

Contents?: true

Size: 1.14 KB

Versions: 17

Compression:

Stored size: 1.14 KB

Contents

require_relative '../../../core/header_collection'

module Datadog
  module Tracing
    module Contrib
      module Rack
        # Classes and utilities for handling headers in Rack.
        module Header
          # An implementation of a header collection that looks up headers from a Rack environment.
          class RequestHeaderCollection < Datadog::Core::HeaderCollection
            # Creates a header collection from a rack environment.
            def initialize(env)
              super()
              @env = env
            end

            # Gets the value of the header with the given name.
            def get(header_name)
              @env[Header.to_rack_header(header_name)]
            end

            # Allows this class to have a similar API to a {Hash}.
            alias [] get

            # Tests whether a header with the given name exists in the environment.
            def key?(header_name)
              @env.key?(Header.to_rack_header(header_name))
            end
          end

          def self.to_rack_header(name)
            "HTTP_#{name.to_s.upcase.gsub(/[-\s]/, '_')}"
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ddtrace-1.23.3 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.23.2 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.23.1 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.22.0 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.21.1 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.21.0 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.20.0 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.19.0 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.18.0 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.17.0 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.16.2 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.16.1 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.16.0 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.15.0 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.14.0 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.13.1 lib/datadog/tracing/contrib/rack/header_collection.rb
ddtrace-1.13.0 lib/datadog/tracing/contrib/rack/header_collection.rb