mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Correctly merge default headers with request provided headers - fixes #255
This commit is contained in:
parent
87f00323c0
commit
212e63aa3e
3 changed files with 16 additions and 2 deletions
|
@ -494,10 +494,17 @@ module HTTParty
|
|||
|
||||
def perform_request(http_method, path, options, &block) #:nodoc:
|
||||
options = default_options.merge(options)
|
||||
process_headers(options)
|
||||
process_cookies(options)
|
||||
Request.new(http_method, path, options).perform(&block)
|
||||
end
|
||||
|
||||
def process_headers(options)
|
||||
if options[:headers] && headers.any?
|
||||
options[:headers] = headers.merge(options[:headers])
|
||||
end
|
||||
end
|
||||
|
||||
def process_cookies(options) #:nodoc:
|
||||
return unless options[:cookies] || default_cookies.any?
|
||||
options[:headers] ||= headers.dup
|
||||
|
|
|
@ -160,12 +160,18 @@ describe HTTParty do
|
|||
@klass.get('')
|
||||
end
|
||||
|
||||
it "overwrites class headers when passing in headers" do
|
||||
expect_headers(:baz => 'spax')
|
||||
it "merges class headers with request headers" do
|
||||
expect_headers(:baz => 'spax', :foo => 'bar')
|
||||
@klass.headers(:foo => 'bar')
|
||||
@klass.get('', :headers => {:baz => 'spax'})
|
||||
end
|
||||
|
||||
it 'overrides class headers with request headers' do
|
||||
expect_headers(:baz => 'spax', :foo => 'baz')
|
||||
@klass.headers(:foo => 'bar')
|
||||
@klass.get('', :headers => {:baz => 'spax', :foo => 'baz'})
|
||||
end
|
||||
|
||||
context "with cookies" do
|
||||
it 'utilizes the class-level cookies' do
|
||||
expect_headers(:foo => 'bar', 'cookie' => 'type=snickerdoodle')
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
$:.push File.expand_path("../lib", __FILE__)
|
||||
|
||||
require "httparty"
|
||||
|
||||
require 'spec/autorun'
|
||||
|
|
Loading…
Reference in a new issue