Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rocket should show 405 instead of 404 for method not allowed #1224

Open
silvioprog opened this issue Feb 8, 2020 · 2 comments · May be fixed by #2616
Open

Rocket should show 405 instead of 404 for method not allowed #1224

silvioprog opened this issue Feb 8, 2020 · 2 comments · May be fixed by #2616
Labels
request Request for new functionality
Milestone

Comments

@silvioprog
Copy link

Hi.

Consider the following route:

#[post("/hello")]
pub fn hello() -> &'static str {
    "Hello"
}

now, if you call it with:

curl http://localhost:8000/hello

it returns:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>404 Not Found</title>
  </head>
  <body align="center">
    <div align="center">
      <h1>404: Not Found</h1>
      <p>The requested resource could not be found.</p>
      <hr />
      <small>Rocket</small>
    </div>
  </body>
</html>

however, since the passed URL is correct and only the method (verb) is wrong, according to rfc7231#section-6.5.5, it should return 405: Method Not Allowed with an Allow header field in a 405 response containing a list of the target resource's currently supported methods.

So, if you don't agree with that, could you provide a global option to send 405 instead of 404 for handling method not allowed errors?

TIA

@jebrosen jebrosen added the request Request for new functionality label Feb 8, 2020
@jebrosen
Copy link
Collaborator

From https://tools.ietf.org/html/rfc7231#section-4.1:

When a request method is received that is known by an origin
server but not allowed for the target resource, the origin server
SHOULD respond with the 405 (Method Not Allowed) status code.

I sounds like a good idea to default to 405 instead of 404, then - and applications that want a 404 can add a 405 catcher that returns a 404.

@bharathk005
Copy link

@SergioBenitez does #2616 fix this or do we still need a solution?

jespersm added a commit to jespersm/Rocket that referenced this issue Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Request for new functionality
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

4 participants