1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Added a 'headers' accessor to the response with a hash of any HTTP

headers.

Signed-off-by: John Nunemaker <nunemaker@gmail.com>
This commit is contained in:
Don Petersen 2009-01-29 14:44:55 +08:00 committed by John Nunemaker
parent 5a210c1562
commit 5c42a98397
3 changed files with 12 additions and 3 deletions

View file

@ -93,7 +93,7 @@ module HTTParty
perform
else
parsed_response = parse_response(response.body)
Response.new(parsed_response, response.body, response.code)
Response.new(parsed_response, response.body, response.code, response.to_hash)
end
end

View file

@ -1,11 +1,12 @@
module HTTParty
class Response < BlankSlate
attr_accessor :body, :code
attr_accessor :body, :code, :headers
def initialize(delegate, body, code)
def initialize(delegate, body, code, headers)
@delegate = delegate
@body = body
@code = code
@headers = headers
end
def method_missing(name, *args, &block)

View file

@ -93,6 +93,14 @@ describe HTTParty::Request do
@request.options[:format] = :json
@request.send(:parse_response, json).should == {'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}}
end
it "should include any HTTP headers in the returned response" do
@request.options[:format] = :html
response = stub_response "Content"
response.initialize_http_header("key" => "value")
@request.perform.headers.should eql({ "key" => ["value"] })
end
describe 'with non-200 responses' do