Module: Petit::RackHelper
- Defined in:
- lib/petit/rack_helper.rb
Class Method Summary collapse
-
.cached(headers = {}, max_age = 7200) ⇒ Object
Appends HTTP cache headers to the hash.
-
.redirect_headers(url) ⇒ Object
Generates a CGI-like redirect header hash for the given url
url
redirect url. -
.redirect_response(url) ⇒ Object
Generates a three part cached response for redirects with the url provided.
Class Method Details
.cached(headers = {}, max_age = 7200) ⇒ Object
Appends HTTP cache headers to the hash
headers - Hash http headers
max_age - Cache expire maximum age (default: 7200)
Returns a Hash
44 45 46 |
# File 'lib/petit/rack_helper.rb', line 44 def cached(headers={}, max_age = 7200) headers.merge({'Cache-Control' => "max-age=#{max_age}, public"}) end |
.redirect_headers(url) ⇒ Object
Generates a CGI-like redirect header hash for the given url
+url+ redirect url
Returns an array
31 32 33 34 35 36 |
# File 'lib/petit/rack_helper.rb', line 31 def redirect_headers(url) { "Content-Type" => "text/plain", "Location" => url } end |
.redirect_response(url) ⇒ Object
Generates a three part cached response for redirects with the url provided
Example:
RackHelper.redirect_response("http://foo.com")
# above will return:
# [ 301,
# {
# "Content-Type" => "text/plain",
# "Location" => "http://foo.com",
# "Cache-Control" => "max-age=7200, public"
# },
# [""]
# ]
Returns an array
22 23 24 |
# File 'lib/petit/rack_helper.rb', line 22 def redirect_response(url) [301, cached(redirect_headers(url)), [""]] end |