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
- #merge_headers(h) ⇒ Object
- #raise_for_status ⇒ Object
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 @options = request. @version = version @status = Integer(status) @headers = @options.headers_class.new(headers) @body = @options.response_body_class.new(self, threshold_size: @options.body_threshold_size, window_size: @options.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
55 56 57 |
# File 'lib/httpx/response.rb', line 55 def inspect "#<Response:#{object_id} @status=#{@status} @headers=#{@headers}>" 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
59 60 61 62 63 |
# File 'lib/httpx/response.rb', line 59 def raise_for_status return if @status < 400 raise HTTPError, self end |