mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-19 05:29:46 +08:00
* fix(http): enforce HTTP/1.1 Host requirement - Enforce Node's default Host behavior while preserving opt-out and HTTP/1.0 handling. - Match the 400 wire response and add C/LLVM differential coverage. * feat(http): add static HTTP trailer and streaming support - Parse incoming chunk trailers and expose distinct/raw trailer reads. - Frame outgoing trailers and add streaming controls with differential coverage. * fix(http): harden request trailer parsing - Safely discard trailers after early responses while preserving parser validation. - Bound aggregate head and trailer parsing by bytes and field count. - Add regressions for early response trailers and overflow rejection.
29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
import { connect } from "node:net";
|
|
|
|
function request(port, wire) {
|
|
return new Promise((resolve, reject) => {
|
|
const socket = connect(port, "127.0.0.1");
|
|
const chunks = [];
|
|
socket.on("connect", () => socket.write(wire));
|
|
socket.on("data", (chunk) => chunks.push(chunk));
|
|
socket.on("end", () => resolve(Buffer.concat(chunks).toString("latin1")));
|
|
socket.on("error", reject);
|
|
});
|
|
}
|
|
|
|
export async function run(port, requireHostHeader = true) {
|
|
const cases = [
|
|
["missing-host", "GET /missing HTTP/1.1\r\nConnection: close\r\n\r\n"],
|
|
["http-1.0", "GET /legacy HTTP/1.0\r\nConnection: close\r\n\r\n"],
|
|
["mixed-case-host", "GET /mixed HTTP/1.1\r\nhOsT: localhost\r\nConnection: close\r\n\r\n"],
|
|
["valid-host", "GET /quit HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n"],
|
|
];
|
|
for (const [name, wire] of cases) {
|
|
const response = await request(port, wire);
|
|
console.log(name + " -> " + response.split("\r\n", 1)[0]);
|
|
if (name === "missing-host" && requireHostHeader) {
|
|
console.log("missing-host wire -> " + JSON.stringify(response.replace(/^Date: .*\r\n/m, "Date: <now>\r\n")));
|
|
}
|
|
}
|
|
}
|