Class: Utopia::Content::Response
- Inherits:
-
Object
- Object
- Utopia::Content::Response
- Defined in:
- lib/utopia/content/response.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#cache!(duration = 3600, access: "public") ⇒ Object
Specify that the content should be cached.
-
#content_type=(value) ⇒ Object
(also: #content_type!)
Specify the content type of the response data.
-
#do_not_cache! ⇒ Object
Specifies that the content shouldn’t be cached.
-
#initialize ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
29 30 31 32 |
# File 'lib/utopia/content/response.rb', line 29 def initialize @status = 200 @headers = {} end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
35 36 37 |
# File 'lib/utopia/content/response.rb', line 35 def headers @headers end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
34 35 36 |
# File 'lib/utopia/content/response.rb', line 34 def status @status end |
Instance Method Details
#cache!(duration = 3600, access: "public") ⇒ Object
Specify that the content should be cached.
44 45 46 47 48 49 |
# File 'lib/utopia/content/response.rb', line 44 def cache!(duration = 3600, access: "public") unless @headers[CACHE_CONTROL] =~ /no-cache/ @headers[CACHE_CONTROL] = "#{access}, max-age=#{duration}" @headers[EXPIRES] = (Time.now + duration).httpdate end end |
#content_type=(value) ⇒ Object Also known as: content_type!
Specify the content type of the response data.
52 53 54 |
# File 'lib/utopia/content/response.rb', line 52 def content_type= value @headers[CONTENT_TYPE] = value end |
#do_not_cache! ⇒ Object
Specifies that the content shouldn’t be cached. Overrides ‘cache!` if already called.
38 39 40 41 |
# File 'lib/utopia/content/response.rb', line 38 def do_not_cache! @headers[CACHE_CONTROL] = "no-cache, must-revalidate" @headers[EXPIRES] = Time.now.httpdate end |