Class: Rack::HostRedirect
- Inherits:
-
Object
- Object
- Rack::HostRedirect
- Defined in:
- lib/rack/host_redirect.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, host_mapping) ⇒ HostRedirect
constructor
A new instance of HostRedirect.
Constructor Details
#initialize(app, host_mapping) ⇒ HostRedirect
Returns a new instance of HostRedirect.
6 7 8 9 |
# File 'lib/rack/host_redirect.rb', line 6 def initialize(app, host_mapping) @app = app @host_mapping = preprocess_mapping(host_mapping) end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rack/host_redirect.rb', line 11 def call(env) request = Rack::Request.new(env) host = request.host.downcase # downcase for case-insensitive matching if updated_uri_opts = @host_mapping[host] location = update_url(request.url, updated_uri_opts) [301, {'Location' => location, 'Content-Type' => 'text/html', 'Content-Length' => '0'}, []] else @app.call(env) end end |