aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2015-03-20 08:09:53 -0400
committereileencodes <eileencodes@gmail.com>2015-03-20 08:48:00 -0400
commit0755d300170d1ef2f6d78f76d0126e962167be5a (patch)
treedb960004bab383536eb881c925df5ab014047b5c /railties
parent2753ffc63e70016f07b871c32c98f06dc35a781a (diff)
downloadrails-0755d300170d1ef2f6d78f76d0126e962167be5a.tar.gz
rails-0755d300170d1ef2f6d78f76d0126e962167be5a.tar.bz2
rails-0755d300170d1ef2f6d78f76d0126e962167be5a.zip
Use fullpath from Rack request rather than building it
In Rack, `#fullpath` checks if there is a query string and builds the query correctly: ``` def path script_name + path_info end def fullpath query_string.empty? ? path : "#{path}?#{query_string}" end ``` We can utilize this instead of manually building the fullpath because they are the same result. This also reduces allocations in `#call` because we don't need `build_original_fullpath` to create the paths and query strings. We don't need to build `fullpath` twice.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/application.rb16
1 files changed, 5 insertions, 11 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index ff6c905f3e..ad6ec1264d 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -159,8 +159,9 @@ module Rails
# Implements call according to the Rack API. It simply
# dispatches the request to the underlying middleware stack.
def call(env)
- env["ORIGINAL_FULLPATH"] = build_original_fullpath(env)
- env["ORIGINAL_SCRIPT_NAME"] = env["SCRIPT_NAME"]
+ req = ActionDispatch::Request.new env
+ env["ORIGINAL_FULLPATH"] = req.fullpath
+ env["ORIGINAL_SCRIPT_NAME"] = req.script_name
super(env)
end
@@ -505,15 +506,8 @@ module Rails
end
def build_original_fullpath(env) #:nodoc:
- path_info = env["PATH_INFO"]
- query_string = env["QUERY_STRING"]
- script_name = env["SCRIPT_NAME"]
-
- if query_string.present?
- "#{script_name}#{path_info}?#{query_string}"
- else
- "#{script_name}#{path_info}"
- end
+ req = ActionDispatch::Request.new env
+ env["ORIGINAL_FULLPATH"] = req.fullpath
end
def validate_secret_key_config! #:nodoc: