Class: HTTPX::Response
- Inherits:
-
Object
- Object
- HTTPX::Response
- Extended by:
- Forwardable
- Defined in:
- lib/httpx/response.rb
Defined Under Namespace
Classes: Body
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #bodyless? ⇒ Boolean
- #complete? ⇒ Boolean
- #content_type ⇒ Object
-
#initialize(request, status, version, headers) ⇒ Response
constructor
A new instance of Response.
-
#inspect ⇒ Object
:nocov:.
- #merge_headers(h) ⇒ Object
-
#raise_for_status ⇒ Object
:nocov:.
Constructor Details
#initialize(request, status, version, headers) ⇒ Response
Returns a new instance of Response.
24 25 26 27 28 29 30 31 32 |
# File 'lib/httpx/response.rb', line 24 def initialize(request, status, version, headers) @request = request = request. @version = version @status = Integer(status) @headers = .headers_class.new(headers) @body = .response_body_class.new(self, threshold_size: .body_threshold_size, window_size: .window_size) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/httpx/response.rb', line 12 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/httpx/response.rb', line 12 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/httpx/response.rb', line 12 def status @status end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
12 13 14 |
# File 'lib/httpx/response.rb', line 12 def version @version end |
Instance Method Details
#<<(data) ⇒ Object
38 39 40 |
# File 'lib/httpx/response.rb', line 38 def <<(data) @body.write(data) end |
#bodyless? ⇒ Boolean
42 43 44 45 |
# File 'lib/httpx/response.rb', line 42 def bodyless? @request.verb == :head || no_data? end |
#complete? ⇒ Boolean
51 52 53 |
# File 'lib/httpx/response.rb', line 51 def complete? bodyless? || (@request.verb == :connect && @status == 200) end |
#content_type ⇒ Object
47 48 49 |
# File 'lib/httpx/response.rb', line 47 def content_type ContentType.parse(@headers["content-type"]) end |
#inspect ⇒ Object
:nocov:
56 57 58 59 60 61 62 |
# File 'lib/httpx/response.rb', line 56 def inspect "#<Response:#{object_id} "\ "HTTP/#{version} " \ "@status=#{@status} " \ "@headers=#{@headers} " \ "@body=#{@body.bytesize}>" end |
#merge_headers(h) ⇒ Object
34 35 36 |
# File 'lib/httpx/response.rb', line 34 def merge_headers(h) @headers = @headers.merge(h) end |
#raise_for_status ⇒ Object
:nocov:
65 66 67 68 69 |
# File 'lib/httpx/response.rb', line 65 def raise_for_status return if @status < 400 raise HTTPError, self end |