Skip to content

Commit

Permalink
[node-fetch#1576] Fixes unexpected premature close on chunked responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Treverix authored Dec 5, 2022
1 parent 55a4870 commit 625fd38
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {


// Sometimes final 0-length chunk and end of message code are in separate packets // Sometimes final 0-length chunk and end of message code are in separate packets
if (!properLastChunkReceived && previousChunk) { if (!properLastChunkReceived && previousChunk) {
properLastChunkReceived = ( if (buf.length < 5) {
Buffer.compare(previousChunk.slice(-3), LAST_CHUNK.slice(0, 3)) === 0 && properLastChunkReceived = Buffer.compare(
Buffer.compare(buf.slice(-2), LAST_CHUNK.slice(3)) === 0 Buffer.from([...previousChunk.slice(-5), ...buf]).slice(-5), LAST_CHUNK) === 0;
); }
} }


previousChunk = buf; previousChunk = buf;
Expand Down

0 comments on commit 625fd38

Please sign in to comment.