Class: Reel::Response
- Inherits:
-
Object
- Object
- Reel::Response
- Defined in:
- lib/reel/response.rb,
lib/reel/response/writer.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Writer
Constant Summary collapse
- CONTENT_LENGTH =
'Content-Length'.freeze
- TRANSFER_ENCODING =
'Transfer-Encoding'.freeze
- CHUNKED =
'chunked'.freeze
- STATUS_CODES =
Use status code tables from the HTTP gem
HTTP::Response::Status::REASONS
- SYMBOL_TO_STATUS_CODE =
Hash[STATUS_CODES.map { |k, v| [v.downcase.gsub(/\s|-/, '_').to_sym, k] }].freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#reason ⇒ Object
Reason can be set explicitly if desired.
-
#status ⇒ Object
Status has a special setter to coerce symbol names.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #chunked? ⇒ Boolean
-
#initialize(status, body_or_headers = nil, body = nil) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(status, body_or_headers = nil, body = nil) ⇒ Response
Returns a new instance of Response.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/reel/response.rb', line 17 def initialize(status, body_or_headers = nil, body = nil) self.status = status if body_or_headers.is_a?(Hash) headers = body_or_headers.dup @body = body else headers = {} @body = body_or_headers end case @body when String headers[CONTENT_LENGTH] ||= @body.bytesize when IO headers[CONTENT_LENGTH] ||= @body.stat.size when Enumerable headers[TRANSFER_ENCODING] ||= CHUNKED when NilClass else raise TypeError, "can't render #{@body.class} as a response body" end @headers = HTTP::Headers.coerce(headers) @version = http_version end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
15 16 17 |
# File 'lib/reel/response.rb', line 15 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
15 16 17 |
# File 'lib/reel/response.rb', line 15 def headers @headers end |
#reason ⇒ Object
Reason can be set explicitly if desired
14 15 16 |
# File 'lib/reel/response.rb', line 14 def reason @reason end |
#status ⇒ Object
Status has a special setter to coerce symbol names
13 14 15 |
# File 'lib/reel/response.rb', line 13 def status @status end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
15 16 17 |
# File 'lib/reel/response.rb', line 15 def version @version end |
Instance Method Details
#chunked? ⇒ Boolean
43 44 45 |
# File 'lib/reel/response.rb', line 43 def chunked? headers[TRANSFER_ENCODING].to_s == CHUNKED end |