Class: Utopia::Content::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/utopia/content/response.rb

Direct Known Subclasses

Transaction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

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

#headersObject (readonly)

Returns the value of attribute headers.



35
36
37
# File 'lib/utopia/content/response.rb', line 35

def headers
  @headers
end

#statusObject (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