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:
parent
5a210c1562
commit
5c42a98397
3 changed files with 12 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue