/usr/lib/ruby/vendor_ruby/rack/mount/prefix.rb is in ruby-rack-mount 0.8.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | require 'rack/mount/utils'
module Rack::Mount
class Prefix #:nodoc:
EMPTY_STRING = ''.freeze
PATH_INFO = 'PATH_INFO'.freeze
SCRIPT_NAME = 'SCRIPT_NAME'.freeze
SLASH = '/'.freeze
KEY = 'rack.mount.prefix'.freeze
def initialize(app, prefix = nil)
@app, @prefix = app, prefix
freeze
end
def call(env)
if prefix = env[KEY] || @prefix
old_path_info = env[PATH_INFO].dup
old_script_name = env[SCRIPT_NAME].dup
begin
env[PATH_INFO] = env[PATH_INFO].sub(prefix, EMPTY_STRING)
env[PATH_INFO] = EMPTY_STRING if env[PATH_INFO] == SLASH
env[SCRIPT_NAME] = Utils.normalize_path(env[SCRIPT_NAME].to_s + prefix)
@app.call(env)
ensure
env[PATH_INFO] = old_path_info
env[SCRIPT_NAME] = old_script_name
end
else
@app.call(env)
end
end
end
end
|