Class: HTTPI::Response
- Inherits:
-
Object
- Object
- HTTPI::Response
- Defined in:
- lib/httpi/response.rb
Overview
HTTPI::Response
Represents an HTTP response and contains various response details.
Constant Summary collapse
- SuccessfulResponseCodes =
Range of HTTP response codes considered to be successful.
200..299
- RedirectResponseCodes =
HTTP response codes considered to be a redirect.
[301, 302, 303, 307, 308]
Instance Attribute Summary collapse
-
#attachments ⇒ Object
Returns any DIME attachments.
-
#body ⇒ Object
Returns the HTTP response body.
-
#code ⇒ Object
Returns the value of attribute code.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#raw_body ⇒ Object
Returns the value of attribute raw_body.
Instance Method Summary collapse
-
#cookies ⇒ Object
Returns a list of cookies from the response.
-
#error? ⇒ Boolean
Returns whether the HTTP response is considered successful.
-
#initialize(code, headers, body) ⇒ Response
constructor
Initializer expects an HTTP response
code
,headers
andbody
. -
#multipart? ⇒ Boolean
Returns whether the HTTP response is a multipart response.
Constructor Details
Instance Attribute Details
#attachments ⇒ Object
Returns any DIME attachments.
46 47 48 49 50 |
# File 'lib/httpi/response.rb', line 46 def @body ||= nil decode_body unless @body @attachments ||= [] end |
#body ⇒ Object
Returns the HTTP response body.
53 54 55 56 57 |
# File 'lib/httpi/response.rb', line 53 def body @body ||= nil decode_body unless @body @body end |
#code ⇒ Object
Returns the value of attribute code.
27 28 29 |
# File 'lib/httpi/response.rb', line 27 def code @code end |
#headers ⇒ Object
Returns the value of attribute headers.
27 28 29 |
# File 'lib/httpi/response.rb', line 27 def headers @headers end |
#raw_body ⇒ Object
Returns the value of attribute raw_body.
27 28 29 |
# File 'lib/httpi/response.rb', line 27 def raw_body @raw_body end |
Instance Method Details
#cookies ⇒ Object
Returns a list of cookies from the response.
41 42 43 |
# File 'lib/httpi/response.rb', line 41 def @cookies ||= Cookie.list_from_headers(headers) end |
#error? ⇒ Boolean
Returns whether the HTTP response is considered successful.
31 32 33 |
# File 'lib/httpi/response.rb', line 31 def error? !SuccessfulResponseCodes.include? code.to_i end |
#multipart? ⇒ Boolean
Returns whether the HTTP response is a multipart response.
36 37 38 |
# File 'lib/httpi/response.rb', line 36 def multipart? !!(headers["Content-Type"] =~ /^multipart/i) end |