Class: NoWwwRails::Middleware
- Inherits:
-
Object
- Object
- NoWwwRails::Middleware
- Defined in:
- lib/no-www-rails/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
3 4 5 |
# File 'lib/no-www-rails/middleware.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/no-www-rails/middleware.rb', line 7 def call(env) request = Rack::Request.new(env) if request.host.starts_with?("www.") [301, {"Location" => request.url.sub("//www.", "//")}, self] else @app.call(env) end end |
#each(&block) ⇒ Object
17 18 |
# File 'lib/no-www-rails/middleware.rb', line 17 def each(&block) end |