Sha256: fd311c6550052a6a85df73f71dfb8bf988f12fc879512e14f2b1ab9bf6f484d0

Contents?: true

Size: 964 Bytes

Versions: 29

Compression:

Stored size: 964 Bytes

Contents

module ActiveRestClient
  class HeadersList
    STORE_MULTIPLE_VALUES = ["set-cookie"]
    def initialize
      @store = {}
    end

    def []=(key,value)
      key = find_existing(key)
      if STORE_MULTIPLE_VALUES.include?(key.downcase)
        @store[key] ||= []
        @store[key] << value
      else
        @store[key] = value
      end
    end

    def [](key)
      key = find_existing(key)
      @store[key]
    end

    def each(split_multiple_headers = false)
      @store.keys.each do |key|
        value = @store[key]
        if value.is_a?(Array) && split_multiple_headers
          value.each do |inner_value|
            yield(key, inner_value)
          end
        else
          yield(key, value)
        end
      end
    end

    private

    def find_existing(key)
      key_downcase = key.downcase
      @store.keys.each do |found_key|
        return found_key if found_key.downcase == key_downcase
      end
      key
    end

  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
active_rest_client-1.2.0 lib/active_rest_client/headers_list.rb
active_rest_client-1.1.12 lib/active_rest_client/headers_list.rb
active_rest_client-1.1.11 lib/active_rest_client/headers_list.rb
active_rest_client-1.1.10 lib/active_rest_client/headers_list.rb
active_rest_client-1.1.9 lib/active_rest_client/headers_list.rb
active_rest_client-1.1.0 lib/active_rest_client/headers_list.rb
active_rest_client-1.0.9 lib/active_rest_client/headers_list.rb
active_rest_client-1.0.8 lib/active_rest_client/headers_list.rb
active_rest_client-1.0.7 lib/active_rest_client/headers_list.rb
active_rest_client-1.0.6 lib/active_rest_client/headers_list.rb
active_rest_client-1.0.5 lib/active_rest_client/headers_list.rb
active_rest_client-1.0.4 lib/active_rest_client/headers_list.rb
active_rest_client-1.0.3 lib/active_rest_client/headers_list.rb
active_rest_client-1.0.2 lib/active_rest_client/headers_list.rb
active_rest_client-1.0.1 lib/active_rest_client/headers_list.rb
active_rest_client-1.0.0 lib/active_rest_client/headers_list.rb
active_rest_client-0.9.75 lib/active_rest_client/headers_list.rb
active_rest_client-0.9.73 lib/active_rest_client/headers_list.rb
active_rest_client-0.9.72 lib/active_rest_client/headers_list.rb
active_rest_client-0.9.71 lib/active_rest_client/headers_list.rb