Skip to content

Commit d4a8dd4

Browse files
test: add integration test for multi-segment POST body buffering
Add a POST handler to the test server that echoes the received body length, and a test case that POSTs 3000 bytes (> ~1460 byte MTU) from the buildroot guest via curl + dd. Verifies the full body reaches the server after the binary-safe buffering fix.
1 parent 2e022cd commit d4a8dd4

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

tests/devices/fetch_network.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,23 @@ if(isMainThread)
249249
assert(/400 Bad Request/.test(capture), "got error 400");
250250
},
251251
},
252+
{
253+
name: "POST large body to local server",
254+
allow_failure: true,
255+
timeout: 30,
256+
start: () =>
257+
{
258+
// POST a 3000-byte body — larger than one TCP segment (~1460 bytes).
259+
// This exercises the multi-segment body buffering fix.
260+
emulator.serial0_send(`dd if=/dev/zero bs=3000 count=1 2>/dev/null | curl -m 10 -s -X POST --data-binary @- ${SERVER_PORT}.external/post\n`);
261+
emulator.serial0_send("echo -e done\\\\tpost large body\n");
262+
},
263+
end_trigger: "done\tpost large body",
264+
end: (capture) =>
265+
{
266+
assert(/Received 3000 bytes/.test(capture), "server received full 3000 byte body");
267+
},
268+
},
252269
];
253270

254271

@@ -395,6 +412,19 @@ else
395412
response.end("Unknown endpoint");
396413
}
397414
break;
415+
case "POST":
416+
if(request.url === "/post") {
417+
let chunks = [];
418+
request.on("data", chunk => chunks.push(chunk));
419+
request.on("end", () => {
420+
const full = Buffer.concat(chunks);
421+
response.end(`Received ${full.length} bytes`);
422+
});
423+
} else {
424+
response.writeHead(404);
425+
response.end("Unknown POST endpoint");
426+
}
427+
break;
398428
default:
399429
response.writeHead(405);
400430
response.end("Unknown method");

0 commit comments

Comments
 (0)