Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/core/operations/DechunkHTTPResponse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ class DechunkHTTPResponse extends Operation {
const lineEndingsLength = lineEndings.length;
let chunkSize = parseInt(input.slice(0, chunkSizeEnd), 16);
while (!isNaN(chunkSize)) {
if (chunkSize === 0) {
break;
}
chunks.push(input.slice(chunkSizeEnd, chunkSize + chunkSizeEnd));
input = input.slice(chunkSizeEnd + chunkSize + lineEndingsLength);
chunkSizeEnd = input.indexOf(lineEndings) + lineEndingsLength;
chunkSize = parseInt(input.slice(0, chunkSizeEnd), 16);
}
return chunks.join("") + input;
return chunks.join("");
}

}
Expand Down
1 change: 1 addition & 0 deletions tests/operations/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import "./tests/CRCChecksum.mjs";
import "./tests/Crypt.mjs";
import "./tests/CSV.mjs";
import "./tests/DateTime.mjs";
import "./tests/DechunkHTTPResponse.mjs";
import "./tests/DefangIP.mjs";
import "./tests/DisassembleARM.mjs";
import "./tests/DropNthBytes.mjs";
Expand Down
66 changes: 66 additions & 0 deletions tests/operations/tests/DechunkHTTPResponse.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* DechunkHTTPResponse operation tests.
*
* @author Willi Ballenthin
* @copyright Crown Copyright 2026
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";

TestRegister.addTests([
{
name: "Dechunk HTTP response: CRLF line endings",
input: "7\r\nMozilla\r\n9\r\nDeveloper\r\n7\r\nNetwork\r\n0\r\n\r\n",
expectedOutput: "MozillaDeveloperNetwork",
recipeConfig: [
{
op: "Dechunk HTTP response",
args: [],
},
],
},
{
name: "Dechunk HTTP response: LF line endings",
input: "7\nMozilla\n9\nDeveloper\n7\nNetwork\n0\n\n",
expectedOutput: "MozillaDeveloperNetwork",
recipeConfig: [
{
op: "Dechunk HTTP response",
args: [],
},
],
},
{
name: "Dechunk HTTP response: single chunk",
input: "5\r\nHello\r\n0\r\n\r\n",
expectedOutput: "Hello",
recipeConfig: [
{
op: "Dechunk HTTP response",
args: [],
},
],
},
{
name: "Dechunk HTTP response: trailing headers discarded",
input: "7\nMozilla\n9\nDeveloper\n7\nNetwork\n0\nExpires: Wed, 21 Oct 2015 07:28:00 GMT\n",
expectedOutput: "MozillaDeveloperNetwork",
recipeConfig: [
{
op: "Dechunk HTTP response",
args: [],
},
],
},
{
name: "Dechunk HTTP response: hex chunk sizes",
input: "a\r\n0123456789\r\n0\r\n\r\n",
expectedOutput: "0123456789",
recipeConfig: [
{
op: "Dechunk HTTP response",
args: [],
},
],
},
]);