Class: HTTPMe::IndexRedirector
- Inherits:
-
Object
- Object
- HTTPMe::IndexRedirector
- Defined in:
- lib/httpme/index_redirector.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, root: '.') ⇒ IndexRedirector
constructor
A new instance of IndexRedirector.
Constructor Details
#initialize(app, root: '.') ⇒ IndexRedirector
Returns a new instance of IndexRedirector.
3 4 5 6 |
# File 'lib/httpme/index_redirector.rb', line 3 def initialize(app, root: '.') @app = app @root = root end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/httpme/index_redirector.rb', line 8 def call(env) path_info = Rack::Utils.unescape env['PATH_INFO'] path = File.join @root, path_info if File.directory?(path) and !path_info.end_with? '/' return [302, { 'Location' => "#{env['PATH_INFO']}/" }, []] end @app.call env end |