Class: Rack::CanonicalHost::Redirect
- Inherits:
-
Object
- Object
- Rack::CanonicalHost::Redirect
- Defined in:
- lib/rack/canonical_host/redirect.rb
Constant Summary collapse
- HTML_TEMPLATE =
<<-HTML.gsub(/^\s+/, '') <!DOCTYPE html> <html lang="en-US"> <head><title>301 Moved Permanently</title></head> <body> <h1>Moved Permanently</h1> <p>The document has moved <a href="%s">here</a>.</p> </body> </html> HTML
Instance Method Summary collapse
- #canonical? ⇒ Boolean
-
#initialize(env, host, options = {}) ⇒ Redirect
constructor
A new instance of Redirect.
- #response ⇒ Object
Constructor Details
#initialize(env, host, options = {}) ⇒ Redirect
Returns a new instance of Redirect.
17 18 19 20 21 22 23 |
# File 'lib/rack/canonical_host/redirect.rb', line 17 def initialize(env, host, ={}) @env = env @host = host @force_ssl = [:force_ssl] @ignore = Array([:ignore]) @if = Array([:if]) end |
Instance Method Details
#canonical? ⇒ Boolean
25 26 27 |
# File 'lib/rack/canonical_host/redirect.rb', line 25 def canonical? (known? && ssl?) || ignored? || !conditions_match? end |
#response ⇒ Object
29 30 31 32 |
# File 'lib/rack/canonical_host/redirect.rb', line 29 def response headers = { 'Location' => new_url, 'Content-Type' => 'text/html' } [301, headers, [HTML_TEMPLATE % new_url]] end |