Skip to content

Improper 400 response to FOO /endpoint request (expected 501, 405 or 404) #3851

@marcfedorow

Description

@marcfedorow

fiber/router.go

Line 549 in 7ce1722

panic(fmt.Sprintf("add: invalid http method %s\n", method))

I have registered a handler in a following way:

app.Get("/bar", handler)

When I try curl -X PATCH $HOSTNAME/bar, the app returns HTTP/1.1 405 Method Not Allowed and Allow: GET, HEAD.
This is a proper response that is expected and RFC compliant.

When I try curl -X PATCH $HOSTNAME/baz, the app returns HTTP/1.1 404 Not Found.
This is a proper response that is expected and RFC compliant.

When I try curl -X FOO $HOSTNAME/bar, the app returns HTTP/1.1 400 Bad Request, no Allow header and Invalid http method as a plain-text body.

I believe that this is not a proper response. As per RFC 9110, I believe that a response with the 501 status code should be sent instead:

501 Not Implemented
The 501 (Not Implemented) status code indicates that the server does not support the functionality required to fulfill the request. This is the appropriate response when the server does not recognize the request method and is not capable of supporting it for any resource.

In practice, I may also expect 405 response similar to the one to the DELETE request.

When I try curl -X FOO $HOSTNAME/baz, the app returns HTTP/1.1 400 Bad Request, no Allow header and Invalid http method as a plaintext body.

I believe that this is not a proper response. As per RFC 9110, I believe that a response with the 404 status code should be sent instead:

[404 Not Found](https://datatracker.ietf.org/doc/html/rfc9110#name-404-not-found)
The 404 (Not Found) status code indicates that the origin server did not find a current representation for the [target resource](https://datatracker.ietf.org/doc/html/rfc9110#target.resource) or is not willing to disclose that one exists.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions