Permalink
Browse files

Merge pull request #270 from mauricio/issue-256

Correctly merge default headers with request provided headers - fixes #255
  • Loading branch information...
2 parents 87f0032 + 212e63a commit 3b513d848573bf90c862fec90222afa2a888876e @jnunemaker committed Feb 10, 2014
Showing with 16 additions and 2 deletions.
  1. +7 −0 lib/httparty.rb
  2. +8 −2 spec/httparty_spec.rb
  3. +1 −0 spec/spec_helper.rb
View
@@ -494,10 +494,17 @@ def default_options #:nodoc:
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
View
@@ -160,12 +160,18 @@ def expect_headers(header={})
@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')
View
@@ -1,4 +1,5 @@
$:.push File.expand_path("../lib", __FILE__)
+
require "httparty"
require 'spec/autorun'

0 comments on commit 3b513d8

Please sign in to comment.