Class: Rack::NonWwwEnforcer

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/non-www-enforcer.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ NonWwwEnforcer

Returns a new instance of NonWwwEnforcer.



7
8
9
# File 'lib/rack/non-www-enforcer.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/rack/non-www-enforcer.rb', line 11

def call(env)
  req = Rack::Request.new(env)
  url = URI(req.url)
  if url.host =~ /^www\./i
    headers = {'Content-Type' => 'text/html', 'Location' => url.to_s.gsub('www.', '')}
    [301, headers, []]
  else
    @app.call(env)
  end
end