From ab8bf9e152ad75c8b358c85e4c95cfde578de127 Mon Sep 17 00:00:00 2001 From: wycats Date: Sat, 3 Apr 2010 20:23:23 -0700 Subject: * Change the object used in routing constraints to be an instance of ActionDispatch::Request rather than Rack::Request. * Changed ActionDispatch::Request#method to return a String, to be compatible with the Rack::Request superclass. * Changed ActionDispatch::Request#method to return the original method in the case of methodoverride and #request_method not to, to be compatible with Rack::Request --- actionpack/lib/action_dispatch/http/request.rb | 60 +++++++++++++++++--------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'actionpack/lib/action_dispatch/http/request.rb') diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 8b8426b5aa..8560a6fc9c 100755 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -45,47 +45,65 @@ module ActionDispatch HTTP_METHODS = %w(get head put post delete options) HTTP_METHOD_LOOKUP = HTTP_METHODS.inject({}) { |h, m| h[m] = h[m.upcase] = m.to_sym; h } - # Returns the true HTTP request \method as a lowercase symbol, such as - # :get. If the request \method is not listed in the HTTP_METHODS - # constant above, an UnknownHttpMethod exception is raised. + # Returns the HTTP \method that the application should see. + # In the case where the \method was overridden by a middleware + # (for instance, if a HEAD request was converted to a GET, + # or if a _method parameter was used to determine the \method + # the application should use), this \method returns the overridden + # value, not the original. def request_method - method = env["rack.methodoverride.original_method"] || env["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 + end + + # Returns a symbol form of the #request_method + def request_method_symbol + HTTP_METHOD_LOOKUP[request_method] end - # Returns the HTTP request \method used for action processing as a - # lowercase symbol, such as :post. (Unlike #request_method, this - # method returns :get for a HEAD request because the two are - # functionally equivalent from the application's perspective.) + # Returns the original value of the environment's REQUEST_METHOD, + # even if it was overridden by middleware. See #request_method for + # more information. def method - method = env["REQUEST_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 + end + + # Returns a symbol form of the #method + def method_symbol + HTTP_METHOD_LOOKUP[method] end - # Is this a GET (or HEAD) request? Equivalent to request.method == :get. + # Is this a GET (or HEAD) request? + # Equivalent to request.request_method == :get. def get? - method == :get + HTTP_METHOD_LOOKUP[request_method] == :get end - # Is this a POST request? Equivalent to request.method == :post. + # Is this a POST request? + # Equivalent to request.request_method == :post. def post? - method == :post + HTTP_METHOD_LOOKUP[request_method] == :post end - # Is this a PUT request? Equivalent to request.method == :put. + # Is this a PUT request? + # Equivalent to request.request_method == :put. def put? - method == :put + HTTP_METHOD_LOOKUP[request_method] == :put end - # Is this a DELETE request? Equivalent to request.method == :delete. + # Is this a DELETE request? + # Equivalent to request.request_method == :delete. def delete? - method == :delete + HTTP_METHOD_LOOKUP[request_method] == :delete end - # Is this a HEAD request? Since request.method sees HEAD as :get, - # this \method checks the actual HTTP \method directly. + # Is this a HEAD request? + # Equivalent to request.method == :head. def head? - request_method == :head + HTTP_METHOD_LOOKUP[method] == :head end # Provides access to the request's HTTP headers, for example: @@ -96,7 +114,7 @@ module ActionDispatch end def forgery_whitelisted? - method == :get || xhr? || content_mime_type.nil? || !content_mime_type.verify_request? + get? || xhr? || content_mime_type.nil? || !content_mime_type.verify_request? end def media_type -- cgit v1.2.3