class Utopia::Redirection::ClientRedirect
A basic client-side redirect.
Attributes
max_age[R]
status[R]
Public Class Methods
new(app, status: 307, max_age: DEFAULT_MAX_AGE)
click to toggle source
# File lib/utopia/redirection.rb, line 86 def initialize(app, status: 307, max_age: DEFAULT_MAX_AGE) @app = app @status = status @max_age = max_age end
Public Instance Methods
[](path)
click to toggle source
# File lib/utopia/redirection.rb, line 117 def [] path false end
cache_control()
click to toggle source
# File lib/utopia/redirection.rb, line 104 def cache_control # http://jacquesmattheij.com/301-redirects-a-dangerous-one-way-street "max-age=#{self.max_age}" end
call(env)
click to toggle source
# File lib/utopia/redirection.rb, line 121 def call(env) path = env[Rack::PATH_INFO] if redirection = self[path] return redirection end return @app.call(env) end
freeze()
click to toggle source
Calls superclass method
# File lib/utopia/redirection.rb, line 92 def freeze return self if frozen? @status.freeze @max_age.freeze super end
headers(location)
click to toggle source
# File lib/utopia/redirection.rb, line 109 def headers(location) {HTTP::LOCATION => location, HTTP::CACHE_CONTROL => self.cache_control} end
redirect(location)
click to toggle source
# File lib/utopia/redirection.rb, line 113 def redirect(location) return [self.status, self.headers(location), []] end