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.
-
#status ⇒ Integer
Returns the HTTP status code of the response.
Instance Method Details
#body ⇒ String
Returns the content of the response as a string. This contains the contents of any calls to render.
23 24 25 |
# File 'lib/rage/response.rb', line 23 def body @controller.__body[0] || "" end |
#etag ⇒ String?
Returns ETag response header or +nil+ if it's empty.
36 37 38 |
# File 'lib/rage/response.rb', line 36 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.
44 45 46 47 48 |
# File 'lib/rage/response.rb', line 44 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.
29 30 31 |
# File 'lib/rage/response.rb', line 29 def headers @controller.__headers end |
#last_modified ⇒ String?
Returns Last-Modified response header or +nil+ if it's empty.
53 54 55 |
# File 'lib/rage/response.rb', line 53 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.
60 61 62 63 64 |
# File 'lib/rage/response.rb', line 60 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 |
#status ⇒ Integer
Returns the HTTP status code of the response.
17 18 19 |
# File 'lib/rage/response.rb', line 17 def status @controller.__status end |