diff options
author | 2023-07-10 22:04:39 +0900 | |
---|---|---|
committer | 2023-07-10 22:04:39 +0900 | |
commit | 438d54f1869a11a7219f6e93c3bb05f6c52ee27b (patch) | |
tree | bc81cb39d0221b99284c59e3b808ed7c8ac32bba | |
parent | c6e113554832d17a0736fea7491c0985705b7cd9 (diff) | |
download | bun-438d54f1869a11a7219f6e93c3bb05f6c52ee27b.tar.gz bun-438d54f1869a11a7219f6e93c3bb05f6c52ee27b.tar.zst bun-438d54f1869a11a7219f6e93c3bb05f6c52ee27b.zip |
add tests
-rw-r--r-- | test/js/node/http/node-http.test.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/js/node/http/node-http.test.ts b/test/js/node/http/node-http.test.ts index 3e7da9d34..167cb9883 100644 --- a/test/js/node/http/node-http.test.ts +++ b/test/js/node/http/node-http.test.ts @@ -146,6 +146,29 @@ describe("node:http", () => { res.end("Path correct!\n"); return; } + if (reqUrl.pathname === "/customWriteHead") { + function createWriteHead(prevWriteHead, listener) { + let fired = false; + return function writeHead() { + if (!fired) { + fired = true; + listener.call(this); + } + return prevWriteHead.apply(this, arguments); + }; + } + + function addPoweredBy() { + if (!this.getHeader("X-Powered-By")) { + this.setHeader("X-Powered-By", "Bun"); + } + } + + res.writeHead = createWriteHead(res.writeHead, addPoweredBy); + res.setHeader("Content-Type", "text/plain"); + res.end("Hello World"); + return; + } } res.writeHead(200, { "Content-Type": "text/plain" }); @@ -507,6 +530,16 @@ describe("node:http", () => { req.end(); }); }); + it("re-implemented writeHead, issue#3585", done => { + runTest(done, (server, serverPort, done) => { + const req = request(`http://localhost:${serverPort}/customWriteHead`, res => { + expect(res.headers["content-type"]).toBe("text/plain"); + expect(res.headers["x-powered-by"]).toBe("Bun"); + done(); + }); + req.end(); + }); + }); }); describe("signal", () => { |