aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/request.rb
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-06-04 09:47:25 -0700
committerwycats <wycats@gmail.com>2010-06-04 20:11:04 -0700
commitab1407cc5bbfe67f9e59335fe0a4e8ac82d513c6 (patch)
tree5f4365ae691c264f8c38b12999fafe27fd84cd89 /actionpack/lib/action_dispatch/http/request.rb
parentbd9805871b576984e13c3d99558eda27d22c06c5 (diff)
downloadrails-ab1407cc5bbfe67f9e59335fe0a4e8ac82d513c6.tar.gz
rails-ab1407cc5bbfe67f9e59335fe0a4e8ac82d513c6.tar.bz2
rails-ab1407cc5bbfe67f9e59335fe0a4e8ac82d513c6.zip
Improve performance of commonly used request methods
Diffstat (limited to 'actionpack/lib/action_dispatch/http/request.rb')
-rwxr-xr-xactionpack/lib/action_dispatch/http/request.rb26
1 files changed, 19 insertions, 7 deletions
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index 8560a6fc9c..98f4f5ae18 100755
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -52,9 +52,11 @@ module ActionDispatch
# the application should use), this \method returns the overridden
# value, not the original.
def request_method
- method = env["REQUEST_METHOD"]
- HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
- method
+ @request_method ||= begin
+ method = env["REQUEST_METHOD"]
+ HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
+ method
+ end
end
# Returns a symbol form of the #request_method
@@ -66,9 +68,11 @@ module ActionDispatch
# even if it was overridden by middleware. See #request_method for
# more information.
def method
- method = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD']
- HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
- method
+ @method ||= begin
+ method = env["rack.methodoverride.original_method"] || env['REQUEST_METHOD']
+ HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}")
+ method
+ end
end
# Returns a symbol form of the #method
@@ -113,6 +117,10 @@ module ActionDispatch
Http::Headers.new(@env)
end
+ def fullpath
+ @fullpath ||= super
+ end
+
def forgery_whitelisted?
get? || xhr? || content_mime_type.nil? || !content_mime_type.verify_request?
end
@@ -134,6 +142,10 @@ module ActionDispatch
end
alias :xhr? :xml_http_request?
+ def ip
+ @ip ||= super
+ end
+
# Which IP addresses are "trusted proxies" that can be stripped from
# the right-hand-side of X-Forwarded-For
TRUSTED_PROXIES = /^127\.0\.0\.1$|^(10|172\.(1[6-9]|2[0-9]|30|31)|192\.168)\./i
@@ -145,7 +157,7 @@ module ActionDispatch
# delimited list in the case of multiple chained proxies; the last
# address which is not trusted is the originating IP.
def remote_ip
- (@env["action_dispatch.remote_ip"] || ip).to_s
+ @remote_ip ||= (@env["action_dispatch.remote_ip"] || ip).to_s
end
# Returns the lowercase name of the HTTP server software.