summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/http.ts
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2024-05-26 09:32:46 +0200
committerGitHub <noreply@github.com>2024-05-26 09:32:46 +0200
commit8806eac63439a974820ea65dd68aac32b35130fa (patch)
tree2eeb65cb5c4fcc1e72958a5fa336fc368256cfa2 /ext/node/polyfills/http.ts
parentf8975a8ecbdb31e846ff1a583b9cdb0bd8a71fcc (diff)
fix(node): set default http server response code 200 (#23977)
Node sets the default HTTP response status code to 200 on the `ServerResponse`. We initialised it as `undefined` before which caused a problem with 11ty's dev server. Thanks to @vrugtehagel for reporting this issue and finding the correct fix as well 🎉 Fixes https://github.com/denoland/deno/issues/23970
Diffstat (limited to 'ext/node/polyfills/http.ts')
-rw-r--r--ext/node/polyfills/http.ts7
1 files changed, 3 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(