1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

use a request object to reduce string allocations and not know about ENV keys

This commit is contained in:
Aaron Patterson 2015-08-06 15:12:19 -07:00
parent 22625a353e
commit 8f27d6036a
2 changed files with 8 additions and 7 deletions

View file

@ -110,16 +110,17 @@ module ActionDispatch
end end
def call(env) def call(env)
case env['REQUEST_METHOD'] req = ActionDispatch::Request.new env
when 'GET', 'HEAD'
path = env['PATH_INFO'].chomp('/'.freeze) if req.get? || req.head?
path = req.path_info.chomp('/'.freeze)
if match = @file_handler.match?(path) if match = @file_handler.match?(path)
env['PATH_INFO'] = match req.path_info = match
return @file_handler.call(env) return @file_handler.call(req.env)
end end
end end
@app.call(env) @app.call(req.env)
end end
end end
end end

View file

@ -156,7 +156,7 @@ module StaticTests
def test_does_not_modify_path_info def test_does_not_modify_path_info
file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js" file_name = "/gzip/application-a71b3024f80aea3181c09774ca17e712.js"
env = {'PATH_INFO' => file_name, 'HTTP_ACCEPT_ENCODING' => 'gzip'} env = {'PATH_INFO' => file_name, 'HTTP_ACCEPT_ENCODING' => 'gzip', "REQUEST_METHOD" => 'POST'}
@app.call(env) @app.call(env)
assert_equal file_name, env['PATH_INFO'] assert_equal file_name, env['PATH_INFO']
end end