module HttpEventLogger module Event class Headers def initialize(headers) @headers = headers.is_a?(Hash) ? headers : to_hash_if_possible(headers) end def [](name) @headers.is_a?(Hash) ? header_value_for(name) : nil end def to_s @headers.is_a?(Hash) ? @headers.map { |key, value| "#{key}: #{value}" }.join(", ") : @headers end private def to_hash_if_possible(headers) if headers.respond_to?(:reduce) headers.reduce({}) do |hash, header| hash[header[0]] = header[1] hash end else headers end end def header_value_for(name) header = @headers.find { |key, value| key.downcase == name.downcase } header ? header[1] : nil end end end end