fix: don't reject with unusable body when full body was received#373
fix: don't reject with unusable body when full body was received#373BlankParticle wants to merge 1 commit into
Conversation
0918a3c to
9367bbd
Compare
|
Hi @BlankParticle, |
|
Hi @BlankParticle, Thank you for working on this. I confirmed that this PR fixes #370. Using the HTTP/1 parser's That said, a few behaviors make me hesitant to merge it as-is:
I'd like to proceed with the fix from my existing branch instead, which also covers these cases and body-reading paths. I incorporated the parts of this PR that I found valuable in 138386d and 0007a09, and credited you as a co-author on both commits. The scenarios covered by this PR are covered on that branch as well. I hope this approach works for you, and I'd be glad to have your review there. #375 |
|
Hi @usualoma, |
* fix: decode string chunks with the stream encoding When application code has called setEncoding() on the IncomingMessage, data events yield strings in that encoding. Converting those chunks back to bytes as UTF-8 corrupts bodies decoded with another encoding. Decode with incoming.readableEncoding and cover the streamed latin1 case. * fix: recover complete HTTP/1 bodies after client disconnect A client can disconnect after Node has parsed the complete HTTP/1 request but before the application reads it. Recover the untouched buffered body for direct reads, native Request reads, formData(), and raw body streams. Share and cache the recovery result across paths, preserve application errors, reject lossy string encodings, and validate canonical content-length values. Add real-socket and synthetic coverage with bounded waits so regressions fail without leaking the test server. * fix: avoid recovering partially consumed request bodies Inspired by #373. Co-authored-by: BlankParticle <blankparticle@gmail.com> * refactor: extract normalizeAbortError for body read failures Adopts the normalizeAbortError helper from #373. Co-authored-by: BlankParticle <blankparticle@gmail.com> * refactor: reuse disconnected body recovery guard Co-authored-by: BlankParticle <blankparticle@gmail.com> --------- Co-authored-by: BlankParticle <blankparticle@gmail.com>
|
closed in favour of #375 |
fixes #370
premature client disconnects now don't reject with
TypeError: Body is unusableif full body was receivedfor partial body, the rejection message is also made clearer
The test case and initial patch was written by Claude Fable 5 (medium)
I reviewed the code and test cases, manually tested, rewrote some of the stuff and added the normalised abort message