Class: Simple::HTTP::Response
- Inherits:
-
Object
- Object
- Simple::HTTP::Response
- Defined in:
- lib/simple/http/response.rb
Constant Summary collapse
- ContentTypeParser =
Simple::HTTP::ContentTypeParser
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#media_type ⇒ Object
readonly
e.g “text/plain”.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #bytes ⇒ Object
- #checked_content(into:) ⇒ Object
-
#content(into: nil) ⇒ Object
evaluate and potentially parse response.
- #to_s ⇒ Object
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
27 28 29 |
# File 'lib/simple/http/response.rb', line 27 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
26 27 28 |
# File 'lib/simple/http/response.rb', line 26 def headers @headers end |
#media_type ⇒ Object (readonly)
e.g “text/plain”
30 31 32 |
# File 'lib/simple/http/response.rb', line 30 def media_type @media_type end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
25 26 27 |
# File 'lib/simple/http/response.rb', line 25 def @message end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
23 24 25 |
# File 'lib/simple/http/response.rb', line 23 def request @request end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
24 25 26 |
# File 'lib/simple/http/response.rb', line 24 def status @status end |
Class Method Details
.body_permitted?(verb) ⇒ Boolean
13 14 15 16 17 18 |
# File 'lib/simple/http/response.rb', line 13 def body_permitted?(verb) return false if verb == :HEAD return false if verb == :OPTIONS true end |
.build(request:, body:, headers:, status:, message:) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/simple/http/response.rb', line 5 def build(request:, body:, headers:, status:, message:) unless body_permitted?(request.verb) body = nil end new request, body, headers, status, end |
Instance Method Details
#bytes ⇒ Object
48 49 50 |
# File 'lib/simple/http/response.rb', line 48 def bytes @body ? @body.bytesize : 0 end |
#checked_content(into:) ⇒ Object
104 105 106 107 |
# File 'lib/simple/http/response.rb', line 104 def checked_content(into:) check_response_status! content(into: into) end |
#content(into: nil) ⇒ Object
evaluate and potentially parse response
57 58 59 60 61 62 63 64 65 |
# File 'lib/simple/http/response.rb', line 57 def content(into: nil) return parsed_content if into.nil? if parsed_content.is_a?(Array) parsed_content.map { |entry| convert_into(entry, into: into) } else convert_into(parsed_content, into: into) end end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/simple/http/response.rb', line 52 def to_s "#{status} #{.gsub(/\s+$/, "")} (#{bytes} byte)" end |