-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
http.ClientRequest ignores incomplete chunked http response #25081
Comments
According to MDN At the beginning of each chunk you need to explicitly add the length of the current chunk in hexadecimal format, followed by '\r\n' and then the chunk itself, followed by another '\r\n'. The terminating chunk is a regular chunk, with the exception that its length is zero. It is followed by the trailer, which consists of a (possibly empty) sequence of entity header fields. |
@akshayarise |
Any update? |
@bjarketrux you can use https://nodejs.org/api/http.html#http_message_complete res.on('end', function() {
console.log(this.complete);
}) |
@lpinca If you look at the observed and expected behavior sections in the original post you can see that I already use the 'end' event but this is not the issue. This issue is that I cannot distinguish between a normal stream and an abrupted connection which is exactly what I want. |
I can't see where |
Whoops, I should have read the answer instead of complaining about you not reading the question :-D Works absolutely! 🥇 |
When fetching a file via http with header
Transfer-Encoding: chunked
a prematurely disrupted connection (socket) is not handled properly.According to the MDN a chunked response is terminated by a 0-length chunk at the end.
Example code
Observed behavior
Executing the example code will output:
Expected behavior
I would expect the following output:
Note: The code
ERR_INCOMPLETE_CHUNKED_ENCODING
is what Chrome will write when navigating tohttp://localhost:8000
, but I imagine node.js will have another code.Note 2: Data is not called with the 0-size termination message.
Alternative behavior:
The
end
event is called with an error or message saying that the underlying socket was closed but the chunked message was not terminated.If the observed behavior is expected, what can I do to detect an incomplete message? Note that I want to pipe the response into a file so I will not implement the
on('data')
handler.The text was updated successfully, but these errors were encountered: