-
Notifications
You must be signed in to change notification settings - Fork 28.9k
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
Sending a body with a GET request using http.request cannot be received using http.server #3009
Comments
Can you provide a complete example to reproduce the issue? |
|
Here's a quick and easy reproduction case: @Trott The reason its throwing |
The reproduction code clarifies everything. Thanks for doing that. I can definitely see a case for considering this a bug in the userland code and not in Node. But even so, I do wonder if the error message can at least be improved or clarified somehow. I'm not sure there's an easy way to do that without possibly hitting false positives, though. |
IMHO this is behaving as expected. |
I know quite a few api services that accept bodies on GET requests (where clauses, etc). If I were to implement those services in nodejs, this would fail then? |
@tflanagan If you sent a |
Somewhat related to nodejs/node-v0.x-archive#5767 and nodejs/node-v0.x-archive#7575. |
From RFC7231: Sending a body in a GET has always led to undefined behavior. As far as I can tell, there's no bug here. Closing but can reopen if necessary. /cc @nodejs/http |
FYI, in my case I was sending body data in a GET request without sending |
@pagalasoujanya Don't hijack unrelated issues. |
(Note: I hate having to bring this up, but it's just that I wasted a few hours today troubleshooting why an API returned a different result when I used curl vs node client.) From RFC7231
This does not read to me as a prohibition (certainly less so than language in earlier RFC) and considering that there are major applications (e.g. Elasticsearch) that use GET with body for queries, node should add a Content-Length header on a GET request with a body. |
When you send a GET request using http.request to a Node.js server using the built-in http server, the parser throws an error:
Presumably because there was no
Content-Length
orTransfer-Encoding
header. There was neither one of those headers because the http client code setsuseChunkedEncodingByDefault
to false when the method isGET
. The parser hits the end of the headers and then immediately starts assuming any more data is a new HTTP request instead of it possibly being the body.If you make the request and explicitly set the
Content-Length
usingsetHeader
then no parse error is thrown. The HTTP spec says:I'm not sure what the fix is here since turning on chunked encoding for GET might make GET's slower and I also realize this is an unintended use case (or bug in user-land) but I thought I'd bring it up.
The text was updated successfully, but these errors were encountered: