From c6e113554832d17a0736fea7491c0985705b7cd9 Mon Sep 17 00:00:00 2001 From: Hanaasagi Date: Mon, 10 Jul 2023 21:35:10 +0900 Subject: call `writeHead` before send headers Close: #3585 --- src/js/node/http.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/js/node/http.ts b/src/js/node/http.ts index 15b060d5f..0c42b247b 100644 --- a/src/js/node/http.ts +++ b/src/js/node/http.ts @@ -948,7 +948,10 @@ export class ServerResponse extends Writable { #finished = false; // Express "compress" package uses this - _implicitHeader() {} + _implicitHeader() { + const statusMessage = this.statusMessage ?? STATUS_CODES[this.statusCode]; + this.writeHead(this.statusCode, statusMessage, {}); + } _write(chunk, encoding, callback) { if (!this.#firstWrite && !this.headersSent) { @@ -1015,6 +1018,7 @@ export class ServerResponse extends Writable { var data = this.#firstWrite || ""; this.#firstWrite = undefined; this.#finished = true; + this._implicitHeader(); this._reply( new Response(data, { headers: this.#headers, -- cgit v1.2.3