class H2OConfigurator::RedirectHandler

Public Instance Methods

call(env) click to toggle source
# File lib/h2o-configurator/handlers/redirect.rb, line 5
def call(env)
  host_dir = env['HOST_DIR']
  path = env['PATH_INFO']
  redirect_path = host_dir + path.sub(%r{/$}, '') + '.redirect'
  if File.exist?(redirect_path)
    location, status = File.read(redirect_path).split(/\s+/, 2)
    status = status.to_i
    [status, {'location' => location}, []]
  elsif path !~ %r{/$} && File.directory?(host_dir + path)
    [302, {'location' => path + '/'}, []]
  else
    [399, {}, []]
  end
end