Skip to content
Browse files

Merge pull request #10299 from econsultancy/use-method-not-allowed-ex…

…ception

Use MethodNotAllowed exception rather than UnknownHttpMethod
  • Loading branch information...
2 parents f95b06f + ec462b4 commit 0fea87c49fd43a2f0d1a0eb66333a189b39afcc8 @pixeltrix pixeltrix committed
View
5 actionpack/CHANGELOG.md
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* Return a 405 Method Not Allowed response when a request contains an unknown
+ HTTP method.
+
+ *Lewis Marshall*
+
* Add support for extracting the port from the `:host` option passed to `url_for`.
*Andrew White*
View
1 actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
@@ -9,6 +9,7 @@ class ExceptionWrapper
'ActionController::RoutingError' => :not_found,
'AbstractController::ActionNotFound' => :not_found,
'ActionController::MethodNotAllowed' => :method_not_allowed,
+ 'ActionController::UnknownHttpMethod' => :method_not_allowed,
'ActionController::NotImplemented' => :not_implemented,
'ActionController::UnknownFormat' => :not_acceptable,
'ActionController::InvalidAuthenticityToken' => :unprocessable_entity,
View
6 actionpack/test/dispatch/debug_exceptions_test.rb
@@ -29,6 +29,8 @@ def call(env)
raise RuntimeError
when "/method_not_allowed"
raise ActionController::MethodNotAllowed
+ when "/unknown_http_method"
+ raise ActionController::UnknownHttpMethod
when "/not_implemented"
raise ActionController::NotImplemented
when "/unprocessable_entity"
@@ -113,6 +115,10 @@ def setup
assert_response 405
assert_match(/ActionController::MethodNotAllowed/, body)
+ get "/unknown_http_method", {}, {'action_dispatch.show_exceptions' => true}
+ assert_response 405
+ assert_match(/ActionController::UnknownHttpMethod/, body)
+
get "/bad_request", {}, {'action_dispatch.show_exceptions' => true}
assert_response 400
assert_match(/ActionController::BadRequest/, body)
View
6 actionpack/test/dispatch/show_exceptions_test.rb
@@ -10,6 +10,8 @@ def call(env)
raise AbstractController::ActionNotFound
when "/method_not_allowed"
raise ActionController::MethodNotAllowed
+ when "/unknown_http_method"
+ raise ActionController::UnknownHttpMethod
when "/not_found_original_exception"
raise ActionView::Template::Error.new('template', AbstractController::ActionNotFound.new)
else
@@ -41,6 +43,10 @@ def call(env)
get "/method_not_allowed", {}, {'action_dispatch.show_exceptions' => true}
assert_response 405
assert_equal "", body
+
+ get "/unknown_http_method", {}, {'action_dispatch.show_exceptions' => true}
+ assert_response 405
+ assert_equal "", body
end
test "localize rescue error page" do

0 comments on commit 0fea87c

Please sign in to comment.
Something went wrong with that request. Please try again.