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 committed 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
Expand Up @@ -397,10 +397,10 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {

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

previousChunk = buf;
Expand Down

0 comments on commit 625fd38

Please sign in to comment.