mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-19 05:29:46 +08:00
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
// The http-headers-spread driver: one GET with pinned headers (the keys
|
|
// line is arrival-ordered), reading back the outgoing matrix — the
|
|
// formatted number, both set-cookie lines, and the value forwarded
|
|
// through the merged record. Then /quit.
|
|
import { request } from "node:http";
|
|
|
|
const port = Number(process.argv[2]);
|
|
|
|
function go(path) {
|
|
return new Promise((resolve, reject) => {
|
|
const req = request(
|
|
{
|
|
host: "127.0.0.1",
|
|
port,
|
|
path,
|
|
method: "GET",
|
|
headers: { "x-alpha": "a", "x-beta": "b", connection: "close" },
|
|
},
|
|
(res) => {
|
|
const chunks = [];
|
|
res.on("data", (c) => chunks.push(c));
|
|
res.on("end", () => {
|
|
console.log(
|
|
`${path} -> ${res.statusCode} num=${res.headers["x-num"]} cookies=${JSON.stringify(res.headers["set-cookie"] ?? null)} fwd=${res.headers["x-fwd"]} body=${Buffer.concat(chunks).toString("utf8")}`,
|
|
);
|
|
resolve();
|
|
});
|
|
},
|
|
);
|
|
req.on("error", reject);
|
|
req.end();
|
|
});
|
|
}
|
|
|
|
await go("/headers");
|
|
await go("/quit");
|
|
console.log("driver done");
|