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