class HTTPMe::IndexRedirector

Public Class Methods

new(app, root: '.') click to toggle source
# File lib/httpme/index_redirector.rb, line 3
def initialize(app, root: '.')
  @app = app
  @root = root
end

Public Instance Methods

call(env) click to toggle source
# 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