Skip to content

Commit

Permalink
Non-destructive URLMap
Browse files Browse the repository at this point in the history
  • Loading branch information
manveru committed Jan 29, 2009
1 parent cf040ea commit df37a91
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/rack/urlmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ def initialize(map)

def call(env)
path = env["PATH_INFO"].to_s.squeeze("/")
script_name = env['SCRIPT_NAME']
hHost, sName, sPort = env.values_at('HTTP_HOST','SERVER_NAME','SERVER_PORT')
@mapping.each { |host, location, app|
next unless (hHost == host || sName == host \
|| (host.nil? && (hHost == sName || hHost == sName+':'+sPort)))
next unless location == path[0, location.size]
next unless path[location.size] == nil || path[location.size] == ?/
env["SCRIPT_NAME"] += location
env["PATH_INFO"] = path[location.size..-1]
return app.call(env)

return app.call(
env.merge(
'SCRIPT_NAME' => (script_name + location),
'PATH_INFO' => path[location.size..-1]))
}
[404, {"Content-Type" => "text/plain"}, ["Not Found: #{path}"]]
end
Expand Down

0 comments on commit df37a91

Please sign in to comment.