diff --git a/src/js/internal/http.ts b/src/js/internal/http.ts new file mode 100644 index 0000000000..622d51a5db --- /dev/null +++ b/src/js/internal/http.ts @@ -0,0 +1,3 @@ +const kDeprecatedReplySymbol = Symbol("deprecatedReply"); + +export default { kDeprecatedReplySymbol }; diff --git a/src/js/node/http.ts b/src/js/node/http.ts index 18a5b50a31..660dd69653 100644 --- a/src/js/node/http.ts +++ b/src/js/node/http.ts @@ -43,7 +43,6 @@ const firstWriteSymbol = Symbol("firstWrite"); const headersSymbol = Symbol("headers"); const isTlsSymbol = Symbol("is_tls"); const kClearTimeout = Symbol("kClearTimeout"); -const kDeprecatedReplySymbol = Symbol("deprecatedReply"); const kfakeSocket = Symbol("kfakeSocket"); const kHandle = Symbol("handle"); const kRealListen = Symbol("kRealListen"); @@ -64,6 +63,8 @@ const serverSymbol = Symbol.for("::bunternal::"); const kRequest = Symbol("request"); const kEmptyObject = Object.freeze(Object.create(null)); + +const { kDeprecatedReplySymbol } = require("internal/http"); const EventEmitter: typeof import("node:events").EventEmitter = require("node:events"); const { isTypedArray } = require("node:util/types"); const { Duplex, Readable, Stream } = require("node:stream"); @@ -699,7 +700,9 @@ function onServerRequestEvent(this: NodeHTTPServerSocket, event: NodeHTTPRespons } } -Server.prototype = { +const ServerPrototype = { + constructor: Server, + __proto__: EventEmitter.prototype, ref() { this._unref = false; this[serverSymbol]?.ref?.(); @@ -987,13 +990,11 @@ Server.prototype = { pendingError = err; if (rejectFunction) rejectFunction(err); }; - var reply = function (resp) { if (pendingResponse) return; pendingResponse = resp; if (resolveFunction) resolveFunction(resp); }; - const prevIsNextIncomingMessageHTTPS = isNextIncomingMessageHTTPS; isNextIncomingMessageHTTPS = isHTTPS; const http_req = new RequestClass(req, { @@ -1003,16 +1004,12 @@ Server.prototype = { isNextIncomingMessageHTTPS = prevIsNextIncomingMessageHTTPS; const upgrade = http_req.headers.upgrade; - const http_res = new ResponseClass(http_req, { [kDeprecatedReplySymbol]: reply }); - http_req.socket[kInternalSocketData] = [server, http_res, req]; server.emit("connection", http_req.socket); - const rejectFn = err => reject(err); http_req.once("error", rejectFn); http_res.once("error", rejectFn); - if (upgrade) { server.emit("upgrade", http_req, http_req.socket, kEmptyBuffer); } else { @@ -1054,10 +1051,8 @@ Server.prototype = { } return this; }, - - constructor: Server, }; -$setPrototypeDirect.$call(Server.prototype, EventEmitter.prototype); +Server.prototype = ServerPrototype; $setPrototypeDirect.$call(Server, EventEmitter); function assignHeadersSlow(object, req) { @@ -1238,6 +1233,7 @@ function IncomingMessage(req, defaultIncomingOpts) { // Node defaults url and method to null. this.url = ""; this.method = null; + this.rawHeaders = []; } this[noBodySymbol] = diff --git a/src/js/thirdparty/ws.js b/src/js/thirdparty/ws.js index 39143060e5..c661fdf366 100644 --- a/src/js/thirdparty/ws.js +++ b/src/js/thirdparty/ws.js @@ -8,6 +8,7 @@ const http = require("node:http"); const onceObject = { once: true }; const kBunInternals = Symbol.for("::bunternal::"); const readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"]; +const { kDeprecatedReplySymbol } = require("internal/http"); const encoder = new TextEncoder(); const eventIds = { open: 1, @@ -1238,7 +1239,7 @@ class WebSocketServer extends EventEmitter { data: ws[kBunInternals], }) ) { - response._reply(undefined); + response[kDeprecatedReplySymbol](undefined); if (this.clients) { this.clients.add(ws); ws.on("close", () => {