Class: HTTY::Response
Overview
Encapsulates an HTTP(S) response.
Constant Summary collapse
- COOKIES_HEADER_NAME =
'Set-Cookie'
- LOCATION_HEADER_NAME =
'Location'
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the HTTP status associated with the response.
-
#time ⇒ Object
readonly
Returns a benchmark time to receive the response.
Attributes inherited from Payload
Instance Method Summary collapse
-
#cookies ⇒ Object
Returns an array of the cookies belonging to the response.
- #follow_relative_to(request) ⇒ Object
-
#initialize(attributes = {}) ⇒ Response
constructor
Initializes a new HTTY::Response with attribute values specified in the attributes hash.
- #location ⇒ Object
Methods inherited from Payload
#==, #cookies_from, #header, #headers, #headers_with_key
Constructor Details
#initialize(attributes = {}) ⇒ Response
Initializes a new HTTY::Response with attribute values specified in the attributes hash.
Valid attributes keys include:
-
:body
-
:headers
-
:status
23 24 25 26 27 28 |
# File 'lib/htty/response.rb', line 23 def initialize(attributes={}) super attributes @status = attributes[:status] @time = attributes[:time] @already_followed = false end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the HTTP status associated with the response.
10 11 12 |
# File 'lib/htty/response.rb', line 10 def status @status end |
#time ⇒ Object (readonly)
Returns a benchmark time to receive the response.
13 14 15 |
# File 'lib/htty/response.rb', line 13 def time @time end |
Instance Method Details
#cookies ⇒ Object
Returns an array of the cookies belonging to the response.
31 32 33 |
# File 'lib/htty/response.rb', line 31 def (COOKIES_HEADER_NAME) end |
#follow_relative_to(request) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/htty/response.rb', line 35 def follow_relative_to(request) return request if @already_followed location_uri = URI.parse(location_header = location) if location_uri.absolute? request.address location_header else request. path_set(location_uri.path). query_set_all(location_uri.query). fragment_set(location_uri.fragment) end ensure @already_followed = true end |
#location ⇒ Object
50 51 52 |
# File 'lib/htty/response.rb', line 50 def location header(LOCATION_HEADER_NAME, HTTY::NoLocationHeaderError.new) end |