Sha256: 15b97334ef3e56f7047e76b20b6afaed6ec94515ceb06c2f0d7a358f1b0b7123

Contents?: true

Size: 853 Bytes

Versions: 85

Compression:

Stored size: 853 Bytes

Contents

# frozen_string_literal: true

module HTTParty
  class HeadersProcessor
    attr_reader :headers, :options

    def initialize(headers, options)
      @headers = headers
      @options = options
    end

    def call
      return unless options[:headers]

      options[:headers] = headers.merge(options[:headers]) if headers.any?
      options[:headers] = Utils.stringify_keys(process_dynamic_headers)
    end

    private

    def process_dynamic_headers
      options[:headers].each_with_object({}) do |header, processed_headers|
        key, value = header
        processed_headers[key] = if value.respond_to?(:call)
                                   value.arity == 0 ? value.call : value.call(options)
                                 else
                                   value
                                 end
      end
    end
  end
end

Version data entries

85 entries across 85 versions & 3 rubygems

Version Path
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.53 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.52 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.50 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.49 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.48 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.47 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.46 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.45 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.44 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.43 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.42 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.41 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.39 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb
harbr-0.1.38 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/headers_processor.rb