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