Created
September 28, 2010 07:39
-
-
Save remvee/600569 to your computer and use it in GitHub Desktop.
silence ActionController::UnknownHttpMethod exceptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Avoid annoying ActionController::UnknownHttpMethod exceptions like: | |
# | |
# ActionController::UnknownHttpMethod) "CONNECT, accepted HTTP methods are get, head, put, post, delete, and options" | |
# | |
# Install this file in app/metal and these requests will receive a 405 | |
# "Method Not Allowed" status and will be logged under `info'. | |
class IgnoreUnknownHttpMethod | |
def self.call(env) | |
[ | |
if ActionController::Request::HTTP_METHODS.include?(env["REQUEST_METHOD"].downcase) | |
404 # Not Found | |
else | |
Rails.logger.info("Ignoring unknown HTTP method; #{env.inspect}") | |
405 # Method Not Allowed | |
end, {"Content-Type" => "text/plain"}, []] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like you can modify Rails' exception to http status code mapping (at least in Rails 3.2) to do this:
It looks like this entry is in the map by default in Rails 4 so things should work out of the box there.