mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Fixed a bug with request headers getting clobbered
This commit is contained in:
parent
b0cf1e946f
commit
c1366ec2c4
2 changed files with 24 additions and 1 deletions
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue