class Utopia::Content::Response
A basic content response, including useful defaults for typical HTML5 content.
Attributes
body[R]
headers[R]
status[RW]
Public Class Methods
new()
click to toggle source
# File lib/utopia/content/response.rb, line 33 def initialize @status = 200 @headers = {} @body = [] # The default content type: self.content_type = "text/html; charset=utf-8" end
Public Instance Methods
cache!(duration = 3600, access: "public")
click to toggle source
Specify that the content could be cached.
# File lib/utopia/content/response.rb, line 65 def cache!(duration = 3600, access: "public") unless cache_control = @headers[CACHE_CONTROL] and cache_control.include?(NO_CACHE) @headers[CACHE_CONTROL] = "#{access}, max-age=#{duration}" @headers[EXPIRES] = (Time.now + duration).httpdate end end
content()
click to toggle source
# File lib/utopia/content/response.rb, line 46 def content @body.join end
content_type=(value)
click to toggle source
Specify the content type of the response data.
# File lib/utopia/content/response.rb, line 73 def content_type= value @headers[CONTENT_TYPE] = value end
Also aliased as: content_type!
do_not_cache!()
click to toggle source
Specifies that the content shouldn't be cached. Overrides `cache!` if already called.
# File lib/utopia/content/response.rb, line 59 def do_not_cache! @headers[CACHE_CONTROL] = "no-cache, must-revalidate" @headers[EXPIRES] = Time.now.httpdate end
lookup(tag)
click to toggle source
# File lib/utopia/content/response.rb, line 50 def lookup(tag) return nil end
to_a()
click to toggle source
# File lib/utopia/content/response.rb, line 54 def to_a [@status, @headers, @body] end