diff options
-rw-r--r-- | ext/node/polyfills/http.ts | 7 | ||||
-rw-r--r-- | tests/unit_node/http_test.ts | 6 |
2 files changed, 9 insertions, 4 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 07ef66146..6b862ce83 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -1332,7 +1332,7 @@ function onError(self, error, cb) { } export class ServerResponse extends NodeWritable { - statusCode?: number = undefined; + statusCode = 200; statusMessage?: string = undefined; #headers = new Headers({}); #readable: ReadableStream; @@ -1444,8 +1444,7 @@ export class ServerResponse extends NodeWritable { } #ensureHeaders(singleChunk?: Chunk) { - if (this.statusCode === undefined) { - this.statusCode = 200; + if (this.statusCode === 200 && this.statusMessage === undefined) { this.statusMessage = "OK"; } if ( @@ -1460,7 +1459,7 @@ export class ServerResponse extends NodeWritable { this.headersSent = true; this.#ensureHeaders(singleChunk); let body = singleChunk ?? (final ? null : this.#readable); - if (ServerResponse.#bodyShouldBeNull(this.statusCode!)) { + if (ServerResponse.#bodyShouldBeNull(this.statusCode)) { body = null; } this.#resolve( diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts index 0518d935b..9cb409c39 100644 --- a/tests/unit_node/http_test.ts +++ b/tests/unit_node/http_test.ts @@ -1004,6 +1004,12 @@ Deno.test("[node/http] ServerResponse getHeaders", () => { assertEquals(res.getHeaders(), { "bar": "baz", "foo": "bar" }); }); +Deno.test("[node/http] ServerResponse default status code 200", () => { + const req = new http.IncomingMessage(new net.Socket()); + const res = new http.ServerResponse(req); + assertEquals(res.statusCode, 200); +}); + Deno.test("[node/http] maxHeaderSize is defined", () => { assertEquals(http.maxHeaderSize, 16_384); }); |