diff options
author | 2023-07-11 20:10:25 +0900 | |
---|---|---|
committer | 2023-07-11 20:32:09 +0900 | |
commit | 17031936c852c2973eacf0929e762972a76ec7bf (patch) | |
tree | a2416f23b9bd6cae2115c08ea748cb10ce7cffbe | |
parent | 0c2df4ae012fdde46b2f61de17e640111cc9379b (diff) | |
download | bun-17031936c852c2973eacf0929e762972a76ec7bf.tar.gz bun-17031936c852c2973eacf0929e762972a76ec7bf.tar.zst bun-17031936c852c2973eacf0929e762972a76ec7bf.zip |
small fix, check if the method has been reassigned.
-rw-r--r-- | src/js/node/http.ts | 7 | ||||
-rw-r--r-- | src/js/out/modules/node/http.js | 8 | ||||
-rw-r--r-- | test/js/node/http/node-http.test.ts | 2 |
3 files changed, 12 insertions, 5 deletions
diff --git a/src/js/node/http.ts b/src/js/node/http.ts index 253bcf4d8..3a283912e 100644 --- a/src/js/node/http.ts +++ b/src/js/node/http.ts @@ -972,6 +972,7 @@ export class ServerResponse extends Writable { this.#firstWrite = undefined; this._writableState.decodeStrings = false; this.#deferred = undefined; + this.#originalWriteHead = this.writeHead; } req; @@ -989,7 +990,7 @@ export class ServerResponse extends Writable { _removedContLen = false; #deferred: (() => void) | undefined = undefined; #finished = false; - + #originalWriteHead: (statusCode, statusMessage, headers) => ServerResponse; // Express "compress" package uses this _implicitHeader() { // @ts-ignore @@ -1061,7 +1062,9 @@ export class ServerResponse extends Writable { var data = this.#firstWrite || ""; this.#firstWrite = undefined; this.#finished = true; - this._implicitHeader(); + if (this.writeHead !== this.#originalWriteHead) { + this._implicitHeader(); + } this._reply( new Response(data, { headers: this.#headers, diff --git a/src/js/out/modules/node/http.js b/src/js/out/modules/node/http.js index 13ee7fded..9cfaccd04 100644 --- a/src/js/out/modules/node/http.js +++ b/src/js/out/modules/node/http.js @@ -630,7 +630,7 @@ class OutgoingMessage extends Writable { class ServerResponse extends Writable { constructor({ req, reply }) { super(); - this.req = req, this._reply = reply, this.sendDate = !0, this.statusCode = 200, this.headersSent = !1, this.statusMessage = void 0, this.#controller = void 0, this.#firstWrite = void 0, this._writableState.decodeStrings = !1, this.#deferred = void 0; + this.req = req, this._reply = reply, this.sendDate = !0, this.statusCode = 200, this.headersSent = !1, this.statusMessage = void 0, this.#controller = void 0, this.#firstWrite = void 0, this._writableState.decodeStrings = !1, this.#deferred = void 0, this.#originalWriteHead = this.writeHead; } req; _reply; @@ -647,7 +647,9 @@ class ServerResponse extends Writable { _removedContLen = !1; #deferred = void 0; #finished = !1; + #originalWriteHead; _implicitHeader() { + this.writeHead(this.statusCode); } _write(chunk, encoding, callback) { if (!this.#firstWrite && !this.headersSent) { @@ -694,7 +696,9 @@ class ServerResponse extends Writable { _final(callback) { if (!this.headersSent) { var data = this.#firstWrite || ""; - this.#firstWrite = void 0, this.#finished = !0, this._reply(new Response(data, { + if (this.#firstWrite = void 0, this.#finished = !0, this.writeHead !== this.#originalWriteHead) + this._implicitHeader(); + this._reply(new Response(data, { headers: this.#headers, status: this.statusCode, statusText: this.statusMessage ?? STATUS_CODES[this.statusCode] diff --git a/test/js/node/http/node-http.test.ts b/test/js/node/http/node-http.test.ts index 167cb9883..0e7b3ca13 100644 --- a/test/js/node/http/node-http.test.ts +++ b/test/js/node/http/node-http.test.ts @@ -530,7 +530,7 @@ describe("node:http", () => { req.end(); }); }); - it("re-implemented writeHead, issue#3585", done => { + it("reassign writeHead method, issue#3585", done => { runTest(done, (server, serverPort, done) => { const req = request(`http://localhost:${serverPort}/customWriteHead`, res => { expect(res.headers["content-type"]).toBe("text/plain"); |