diff --git a/lib/httparty.rb b/lib/httparty.rb index 0a6100a..4766a48 100644 --- a/lib/httparty.rb +++ b/lib/httparty.rb @@ -155,8 +155,9 @@ module HTTParty private def perform_request(http_method, path, options) #:nodoc: + options = default_options.dup.merge(options) process_cookies(options) - Request.new(http_method, path, default_options.dup.merge(options)).perform + Request.new(http_method, path, options).perform end def process_cookies(options) #:nodoc: diff --git a/spec/httparty_spec.rb b/spec/httparty_spec.rb index 95974dd..becd9d9 100644 --- a/spec/httparty_spec.rb +++ b/spec/httparty_spec.rb @@ -51,6 +51,12 @@ describe HTTParty do end describe "headers" do + def expect_header(type, value) + HTTParty::Request.should_receive(:new) \ + .with(anything, anything, hash_including({ :headers => { type => value, "cookie" => "" } })) \ + .and_return(mock("mock response", :perform => nil)) + end + it "should default to empty hash" do @klass.headers.should == {} end @@ -60,6 +66,22 @@ describe HTTParty do @klass.headers init_headers @klass.headers.should == init_headers end + + describe "when a header is set at the class level" do + before(:each) do + @klass.headers({ 'Content-Type' => 'application/json' }) + end + + it "should include that header in a get request" do + expect_header "Content-Type", "application/json" + @klass.get("") + end + + it "should include that header in a post request" do + expect_header "Content-Type", "application/json" + @klass.post("") + end + end end describe "cookies" do