-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Invalid HTTP method incorrectly returns a 400 instead of a 405 #17248
Comments
node's http parser cannot actually use custom methods, it has them hardcoded |
Hi @Qix- and thanks for your suggestion, but I would argue that the current behavior is, in fact, correct and conforms to the RFC. https://tools.ietf.org/html/rfc7231#section-6.5.1:
https://tools.ietf.org/html/rfc7231#section-6.5.5:
In other words, if Node's HTTP parser cannot parse the request because it can't recognize the method, it should send a 400. A 405 would imply that the server supports the method in general, but it isn't supported for a specific resource a client requests. |
I know - I don't think it should do that. Or, it should be opt-out at the very least. I understand when I'm breaking RFC (see below) to do some proprietary operations on my HTTP server and now Node refuses to let me do that. Node is forcing its opinion on my applications - something that's a bit out of place for Node, IMO.
Which RFC? According to RFC 7231 §4.1 (the same RFC you reference), there is no limitation on the methods - instead, there are a set of standard methods with well-defined semantics, all of which are optional except for I'll cede that |
@Qix- you can override |
@devsnek I'd rather not re-implement Node internals, but thanks for the hint. If it really comes to it, I can do that. I'd imagine it'd be a huge performance penalty if it were done in pure Javascript, though. |
Yes, that's right. But it's a completely different issue and a limitation of Node's HTTP parser. If you'd like to open a feature request, go for it. However, realistically, I wouldn't make any assumptions about how fast such a feature could land in core if it were implemented, and would it eventually land at all given the amount of churn in critical internal code it would most probably cause :( |
The http1 http_parser is written to support a limited range of methods primarily for performance reasons. I've tried changing that before and it ended up with too great of a performance penalty and went no where. At this point, it is exceedingly unlikely to change. Fortunately, the new http2 implementation does not have that problem and supports any HTTP method. As for the response code, returning a 400 response is technically correct as 400 generically covers all 4xx codes -- it's just, admittedly, not as useful. |
Thanks for the answer @jasnell, that makes sense. I'll look into the http2 module as, luckily, we're not constrained by Node version 👍 |
This should be sending a 405 Method Not Allowed, not a 400.
Also, preferably, Node shouldn't care about the method and should happily forward it along in the
req.method
field. But I know that's asking for too much.The text was updated successfully, but these errors were encountered: