Class: Rage::Response
- Inherits:
-
Object
- Object
- Rage::Response
- Defined in:
- lib/rage/response.rb
Constant Summary collapse
- ETAG_HEADER =
"ETag"
- LAST_MODIFIED_HEADER =
"Last-Modified"
Instance Method Summary collapse
-
#body ⇒ String
Returns the content of the response as a string.
-
#etag ⇒ String?
Returns ETag response header or
nil
if it’s empty. -
#etag=(etag) ⇒ Object
Sets ETag header to the response.
-
#headers ⇒ Hash
Returns the headers for the response.
-
#last_modified ⇒ String?
Returns Last-Modified response header or
nil
if it’s empty. -
#last_modified=(last_modified) ⇒ Object
Sets Last-Modified header to the response by calling httpdate on the argument.
Instance Method Details
#body ⇒ String
Returns the content of the response as a string. This contains the contents of any calls to render
.
18 19 20 |
# File 'lib/rage/response.rb', line 18 def body @body[0] end |
#etag ⇒ String?
Returns ETag response header or nil
if it’s empty.
31 32 33 |
# File 'lib/rage/response.rb', line 31 def etag headers[Rage::Response::ETAG_HEADER] end |
#etag=(etag) ⇒ Object
ETag will be always Weak since no strong validation is implemented.
ArgumentError is raised if ETag value is neither String
, nor nil
Sets ETag header to the response. Additionally, it will hashify the value using Digest::SHA1.hexdigest
. Pass nil
for resetting it.
39 40 41 42 43 |
# File 'lib/rage/response.rb', line 39 def etag=(etag) raise ArgumentError, "Expected `String` but `#{etag.class}` is received" unless etag.is_a?(String) || etag.nil? headers[Rage::Response::ETAG_HEADER] = etag.nil? ? nil : %(W/"#{Digest::SHA1.hexdigest(etag)}") end |
#headers ⇒ Hash
Returns the headers for the response.
24 25 26 |
# File 'lib/rage/response.rb', line 24 def headers @headers end |
#last_modified ⇒ String?
Returns Last-Modified response header or nil
if it’s empty.
48 49 50 |
# File 'lib/rage/response.rb', line 48 def last_modified headers[Rage::Response::LAST_MODIFIED_HEADER] end |
#last_modified=(last_modified) ⇒ Object
ArgumentError is raised if last_modified
is not a Time
object instance
Sets Last-Modified header to the response by calling httpdate on the argument.
55 56 57 58 59 |
# File 'lib/rage/response.rb', line 55 def last_modified=(last_modified) raise ArgumentError, "Expected `Time` but `#{last_modified.class}` is received" unless last_modified.is_a?(Time) || last_modified.nil? headers[Rage::Response::LAST_MODIFIED_HEADER] = last_modified&.httpdate end |