Sha256: 48a0535974eae27b9bf0d13859ecec86efbb79c77481a7cb3ca434fb45f04f09

Contents?: true

Size: 1.33 KB

Versions: 35

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Datadog
  module Core
    # A some-what abstract class representing a collection of headers.
    #
    # Use the `HeaderCollection.from_hash` function to create a header collection from a `Hash`.
    # Another option is to use `HashHeaderCollection` directly.
    class HeaderCollection
      # Gets a single value of the header with the given name, case insensitive.
      #
      # @param [String] header_name Name of the header to get the value of.
      # @returns [String, nil] A single value of the header, or nil if the header with
      #   the given name is missing from the collection.
      def get(header_name)
        nil
      end

      # Create a header collection that retrieves headers from the given Hash.
      #
      # This can be useful for testing or other trivial use cases.
      #
      # @param [Hash] hash Hash with the headers.
      def self.from_hash(hash)
        HashHeaderCollection.new(hash)
      end
    end

    # A header collection implementation that looks up headers in a Hash.
    class HashHeaderCollection < HeaderCollection
      def initialize(hash)
        super()
        @hash = {}.tap do |res|
          hash.each_pair { |key, value| res[key.downcase] = value }
        end
      end

      def get(header_name)
        @hash[header_name.downcase]
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
datadog-2.9.0 lib/datadog/core/header_collection.rb
datadog-2.8.0 lib/datadog/core/header_collection.rb
datadog-2.7.1 lib/datadog/core/header_collection.rb
datadog-2.7.0 lib/datadog/core/header_collection.rb
datadog-2.6.0 lib/datadog/core/header_collection.rb
datadog-2.5.0 lib/datadog/core/header_collection.rb
datadog-2.4.0 lib/datadog/core/header_collection.rb
datadog-2.3.0 lib/datadog/core/header_collection.rb
datadog-2.2.0 lib/datadog/core/header_collection.rb
ddtrace-1.23.3 lib/datadog/core/header_collection.rb
ddtrace-1.23.2 lib/datadog/core/header_collection.rb
datadog-2.1.0 lib/datadog/core/header_collection.rb
datadog-2.0.0 lib/datadog/core/header_collection.rb
ddtrace-1.23.1 lib/datadog/core/header_collection.rb
datadog-2.0.0.beta2 lib/datadog/core/header_collection.rb
ddtrace-1.22.0 lib/datadog/core/header_collection.rb
datadog-2.0.0.beta1 lib/datadog/core/header_collection.rb
ddtrace-1.21.1 lib/datadog/core/header_collection.rb
ddtrace-1.21.0 lib/datadog/core/header_collection.rb
ddtrace-1.20.0 lib/datadog/core/header_collection.rb