mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
![Andy Brody](/assets/img/avatar_default.png)
It is redundant and confusing to pass both the Request args and the Request when creating a RestClient::Response. Instead, when the response object needs to read args from the request, access them on the request object itself. For determining the HTTP method of the request, switch to calling RestClient::Request#method. Also normalize the Request#method to be a lowercase string. This makes handling of redirection and other method-specific functionality actually work regardless of how the method was provided to Request.new (:get, 'GET', 'get'). Fixes: #461 Fixes: #462 Fixes: #463
38 lines
985 B
Ruby
38 lines
985 B
Ruby
module RestClient
|
|
# The response from RestClient on a raw request looks like a string, but is
|
|
# actually one of these. 99% of the time you're making a rest call all you
|
|
# care about is the body, but on the occassion you want to fetch the
|
|
# headers you can:
|
|
#
|
|
# RestClient.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.
|
|
class RawResponse
|
|
|
|
include AbstractResponse
|
|
|
|
attr_reader :file, :request
|
|
|
|
def inspect
|
|
"<RestClient::RawResponse @code=#{code.inspect}, @file=#{file.inspect}, @request=#{request.inspect}>"
|
|
end
|
|
|
|
def initialize(tempfile, net_http_res, request)
|
|
@net_http_res = net_http_res
|
|
@file = tempfile
|
|
@request = request
|
|
end
|
|
|
|
def to_s
|
|
@file.open
|
|
@file.read
|
|
end
|
|
|
|
def size
|
|
File.size file
|
|
end
|
|
|
|
end
|
|
end
|