class NoWWW::Middleware
Constants
- IP_STRING
- STARTS_WITH_WWW
Public Class Methods
new(app)
click to toggle source
# File lib/no_w_w_w/middleware.rb, line 6 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/no_w_w_w/middleware.rb, line 10 def call(env) uri = URI.parse Rack::Request.new(env).url unless uri.host =~ STARTS_WITH_WWW || uri.host =~ IP_STRING uri.host = "www.#{uri.host}" puts "NoWWW: Redirected to #{uri.to_s}" [301, { 'Location' => uri.to_s}, ['Redirecting...']] else @app.call(env) end end