-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Server not responding until the request data is processed #3155
Comments
This would be better asked at https://github.com/nodejs/help or stack overflow. The server should be able to respond before reading all of the data. Are you sure the client is not staying alive to send the data though? |
Yes, the client is staying alive, but I want to ignore it. Thanks for the link - I'll surely ask there too, but I thought this was a nodejs issue. |
If you ask on |
It's quite late to add that info, but I actually got redirected here from here: expressjs/express#2765 @dougwilson has written that "The issue here is a Node.js core issue", so I opened an issue here, believing that he has also researched the topic quite a bit. |
Aborting http requests and getting a response before the request body is sent has to be supported on the client. There is an |
In fact, it's there, of course: https://nodejs.org/api/http.html#http_event_checkcontinue |
Thanks a lot, will definitely look into it then! I tried googling before ofc, but I guess sometimes you have to know the exact thing you're looking for... Also it's nice that this question has gotten some attention after a few idle months 😄 |
I've found the answer and I've put it in the first comment for future reference. |
I've created a simple server:
When I'm POST-ing some data (a lot of data) the server won't respond until all of the data has been processed. It is ignored obviously, because there is no
data
event listener set up.The question is, is there a way to skip the wait and still provide a meaningful response?
There is a scenario in which this would be useful: I'd like to limit the data I receive, and respond with an appropriate error immediately after the limit has been reached.
I've read the docs, read some source files, and didn't find the answer. Is it a bug in Node, a limitation of the HTTP protocol, or did I miss something?
The Answer (edited)
So it turns out the browsers are at fault: http://serverfault.com/questions/360479/why-might-a-413-not-be-flushed-to-the-client-immediately. As @ChALkeR has written, the client has to handle the response, but XMLHttpRequest (which I was using) doesn't work like this. There is a chance that the fetch API allows reading the response before the full request is sent (with streams), but I'm not sure about that.
Another option would be to upload using a WebSocket connection. The client in the browser would be able to send a chunked request and listen for a response in the meanwhile. But this is only a workaround, because I want to be able do it with simple HTTP.
The text was updated successfully, but these errors were encountered: