aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-07-11 18:49:35 -0700
committerGravatar GitHub <noreply@github.com> 2023-07-11 18:49:35 -0700
commit8ca2194a371ac5b69af11a71748db16e7cf3262a (patch)
treead14ca22ffc14064ef0524a1837ae6a47119ec3b /src
parent03904f73cce64c91aa770b494ef40e257f212037 (diff)
downloadbun-8ca2194a371ac5b69af11a71748db16e7cf3262a.tar.gz
bun-8ca2194a371ac5b69af11a71748db16e7cf3262a.tar.zst
bun-8ca2194a371ac5b69af11a71748db16e7cf3262a.zip
fix #3597 (#3609)
* fix #3597 * Update http.ts * initialize to true
Diffstat (limited to 'src')
-rw-r--r--src/js/node/http.ts19
-rw-r--r--src/js/out/modules/node/http.js6
2 files changed, 24 insertions, 1 deletions
diff --git a/src/js/node/http.ts b/src/js/node/http.ts
index 42388b32e..fe075c832 100644
--- a/src/js/node/http.ts
+++ b/src/js/node/http.ts
@@ -973,6 +973,10 @@ export class ServerResponse extends Writable {
this.#firstWrite = undefined;
this._writableState.decodeStrings = false;
this.#deferred = undefined;
+
+ // this is matching node's behaviour
+ // https://github.com/nodejs/node/blob/cf8c6994e0f764af02da4fa70bc5962142181bf3/lib/_http_server.js#L192
+ if (req.method === "HEAD") this._hasBody = false;
}
req;
@@ -988,6 +992,7 @@ export class ServerResponse extends Writable {
_defaultKeepAlive = false;
_removedConnection = false;
_removedContLen = false;
+ _hasBody = true;
#deferred: (() => void) | undefined = undefined;
#finished = false;
// Express "compress" package uses this
@@ -1835,6 +1840,20 @@ function _writeHead(statusCode, reason, obj, response) {
}
}
}
+
+ if (statusCode === 204 || statusCode === 304 || (statusCode >= 100 && statusCode <= 199)) {
+ // RFC 2616, 10.2.5:
+ // The 204 response MUST NOT include a message-body, and thus is always
+ // terminated by the first empty line after the header fields.
+ // RFC 2616, 10.3.5:
+ // The 304 response MUST NOT contain a message-body, and thus is always
+ // terminated by the first empty line after the header fields.
+ // RFC 2616, 10.1 Informational 1xx:
+ // This class of status code indicates a provisional response,
+ // consisting only of the Status-Line and optional headers, and is
+ // terminated by an empty line.
+ response._hasBody = false;
+ }
}
/**
diff --git a/src/js/out/modules/node/http.js b/src/js/out/modules/node/http.js
index d0937a945..cc9092518 100644
--- a/src/js/out/modules/node/http.js
+++ b/src/js/out/modules/node/http.js
@@ -99,6 +99,8 @@ var _writeHead = function(statusCode, reason, obj, response) {
response.setHeader(k, obj[k]);
}
}
+ if (statusCode === 204 || statusCode === 304 || statusCode >= 100 && statusCode <= 199)
+ response._hasBody = !1;
};
function request(url, options, cb) {
return new ClientRequest(url, options, cb);
@@ -631,7 +633,8 @@ var OriginalWriteHeadFn, OriginalImplicitHeadFn;
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;
+ if (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, req.method === "HEAD")
+ this._hasBody = !1;
}
req;
_reply;
@@ -646,6 +649,7 @@ class ServerResponse extends Writable {
_defaultKeepAlive = !1;
_removedConnection = !1;
_removedContLen = !1;
+ _hasBody = !0;
#deferred = void 0;
#finished = !1;
_implicitHeader() {