aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-08-06 15:12:19 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-08-06 15:12:19 -0700
commit8f27d6036a2ddc3cb7a7ad98afa2666ec163c2c3 (patch)
tree55e33897b9d3c41ed527e4e459b16660d4b012c4
parent22625a353e8d9613f615a25ec642eb057de19cf1 (diff)
downloadrails-8f27d6036a2ddc3cb7a7ad98afa2666ec163c2c3.tar.gz
rails-8f27d6036a2ddc3cb7a7ad98afa2666ec163c2c3.tar.bz2
rails-8f27d6036a2ddc3cb7a7ad98afa2666ec163c2c3.zip
use a request object to reduce string allocations and not know about ENV keys
-rw-r--r--actionpack/lib/action_dispatch/middleware/static.rb13
-rw-r--r--actionpack/test/dispatch/static_test.rb2
2 files changed, 8 insertions, 7 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb
index f38da4fdf6..5d3c2c3495 100644
--- a/actionpack/lib/action_dispatch/middleware/static.rb
+++ b/actionpack/lib/action_dispatch/middleware/static.rb
@@ -110,16 +110,17 @@ module ActionDispatch
end
def call(env)
- case env['REQUEST_METHOD']
- when 'GET', 'HEAD'
- path = env['PATH_INFO'].chomp('/'.freeze)
+ req = ActionDispatch::Request.new env
+
+ if req.get? || req.head?
+ path = req.path_info.chomp('/'.freeze)
if match = @file_handler.match?(path)
- env['PATH_INFO'] = match
- return @file_handler.call(env)
+ req.path_info = match
+ return @file_handler.call(req.env)
end
end
- @app.call(env)
+ @app.call(req.env)
end
end
end
diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb
index 95971b3a0e..13dec8b618 100644
--- a/actionpack/test/dispatch/static_test.rb
+++ b/actionpack/test/dispatch/static_test.rb
@@ -156,7 +156,7 @@ module StaticTests
def test_does_not_modify_path_info
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)
assert_equal file_name, env['PATH_INFO']
end