Method: Rack::URLMap#call

Defined in:
lib/rack/urlmap.rb

#call(env) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rack/urlmap.rb', line 37

def call(env)
  path = env["PATH_INFO"]
  script_name = env['SCRIPT_NAME']
  hHost, sName, sPort = env.values_at('HTTP_HOST','SERVER_NAME','SERVER_PORT')
  @mapping.each { |host, location, match, app|
    next unless (hHost == host || sName == host \
      || (host.nil? && (hHost == sName || hHost == sName+':'+sPort)))
    next unless path.to_s =~ match && rest = $1
    next unless rest.empty? || rest[0] == ?/
    env.merge!('SCRIPT_NAME' => (script_name + location), 'PATH_INFO' => rest)
    return app.call(env)
  }
  [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{path}"]]
ensure
  env.merge! 'PATH_INFO' => path, 'SCRIPT_NAME' => script_name
end