Sha256: e2bb65b5dfd0b849b2f859be3f9379cf3781193e35e8fb96dac2c7478c1fe0de

Contents?: true

Size: 957 Bytes

Versions: 69

Compression:

Stored size: 957 Bytes

Contents

module Flexirest
  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

69 entries across 69 versions & 1 rubygems

Version Path
flexirest-1.5.5 lib/flexirest/headers_list.rb
flexirest-1.5.4 lib/flexirest/headers_list.rb
flexirest-1.5.3 lib/flexirest/headers_list.rb
flexirest-1.5.2 lib/flexirest/headers_list.rb
flexirest-1.5.1 lib/flexirest/headers_list.rb
flexirest-1.5.0 lib/flexirest/headers_list.rb
flexirest-1.4.9 lib/flexirest/headers_list.rb
flexirest-1.4.8 lib/flexirest/headers_list.rb
flexirest-1.4.7 lib/flexirest/headers_list.rb
flexirest-1.4.6 lib/flexirest/headers_list.rb
flexirest-1.4.5 lib/flexirest/headers_list.rb
flexirest-1.4.4 lib/flexirest/headers_list.rb
flexirest-1.4.3 lib/flexirest/headers_list.rb
flexirest-1.4.2 lib/flexirest/headers_list.rb
flexirest-1.4.1 lib/flexirest/headers_list.rb
flexirest-1.4.0 lib/flexirest/headers_list.rb
flexirest-1.3.35 lib/flexirest/headers_list.rb
flexirest-1.3.34 lib/flexirest/headers_list.rb
flexirest-1.3.33 lib/flexirest/headers_list.rb
flexirest-1.3.32 lib/flexirest/headers_list.rb