Class: Rack::CanonicalHost::Redirect

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(env, host, options = {}) ⇒ Redirect

Returns a new instance of Redirect.



18
19
20
21
22
23
24
# File 'lib/rack/canonical_host/redirect.rb', line 18

def initialize(env, host, options={})
  self.env = env
  self.host = host
  self.ignore = Array(options[:ignore])
  self.conditions = Array(options[:if])
  self.cache_control = options[:cache_control]
end

Instance Method Details

#canonical?Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/rack/canonical_host/redirect.rb', line 26

def canonical?
  return true unless enabled?
  known? || ignored?
end

#responseObject



31
32
33
# File 'lib/rack/canonical_host/redirect.rb', line 31

def response
  [301, headers, [HTML_TEMPLATE % new_url]]
end