Class: Rack::CanonicalHost

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/canonical_host.rb,
lib/rack/canonical_host/version.rb,
lib/rack/canonical_host/redirect.rb

Defined Under Namespace

Classes: Redirect

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Constructor Details

#initialize(app, host = nil, options = {}, &block) ⇒ CanonicalHost

Returns a new instance of CanonicalHost.



7
8
9
10
11
12
# File 'lib/rack/canonical_host.rb', line 7

def initialize(app, host=nil, options={}, &block)
  @app = app
  @host = host
  @options = options
  @block = block
end

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/rack/canonical_host.rb', line 14

def call(env)
  host = host(env)
  redirect = Redirect.new(env, host, @options)

  if redirect.canonical?
    @app.call(env)
  else
    redirect.response
  end
end