Class: HttpClient::RawResponse
- Inherits:
-
Object
- Object
- HttpClient::RawResponse
- Includes:
- Mixin::Response
- Defined in:
- lib/http_client/raw_response.rb
Overview
The response from HttpClient on a raw request looks like a string, but is actually one of these. 99% of the time you’re making a http call all you care about is the body, but on the occassion you want to fetch the headers you can:
HttpClient.get('http://example.com').headers[:content_type]
In addition, if you do not use the response as a string, you can access a Tempfile object at res.file, which contains the path to the raw downloaded request body.
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Attributes included from Mixin::Response
Instance Method Summary collapse
-
#initialize(tempfile, net_http_res) ⇒ RawResponse
constructor
A new instance of RawResponse.
- #to_s ⇒ Object
Methods included from Mixin::Response
#code, #cookies, #headers, included
Constructor Details
#initialize(tempfile, net_http_res) ⇒ RawResponse
Returns a new instance of RawResponse.
19 20 21 22 |
# File 'lib/http_client/raw_response.rb', line 19 def initialize(tempfile, net_http_res) @net_http_res = net_http_res @file = tempfile end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
17 18 19 |
# File 'lib/http_client/raw_response.rb', line 17 def file @file end |
Instance Method Details
#to_s ⇒ Object
24 25 26 27 |
# File 'lib/http_client/raw_response.rb', line 24 def to_s @file.open @file.read end |