diff options
Diffstat (limited to 'ext/node')
-rw-r--r-- | ext/node/polyfills/http.ts | 45 |
1 files changed, 10 insertions, 35 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index ff6dede3f..0529ccca5 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -270,6 +270,9 @@ const kError = Symbol("kError"); const kUniqueHeaders = Symbol("kUniqueHeaders"); +class FakeSocket extends EventEmitter { +} + /** ClientRequest represents the http(s) request from the client */ class ClientRequest extends OutgoingMessage { defaultProtocol = "http:"; @@ -544,6 +547,7 @@ class ClientRequest extends OutgoingMessage { this.onSocket(createConnection(optsWithoutSignal)); } }*/ + this.onSocket(new FakeSocket()); const url = this._createUrlStrFromOptions(); @@ -573,41 +577,12 @@ class ClientRequest extends OutgoingMessage { return undefined; } - onSocket(socket, err) { - if (this.destroyed || err) { - this.destroyed = true; - - // deno-lint-ignore no-inner-declarations - function _destroy(req, err) { - if (!req.aborted && !err) { - err = connResetException("socket hang up"); - } - if (err) { - req.emit("error", err); - } - req._closed = true; - req.emit("close"); - } - - if (socket) { - if (!err && this.agent && !socket.destroyed) { - socket.emit("free"); - } else { - finished(socket.destroy(err || this[kError]), (er) => { - if (er?.code === "ERR_STREAM_PREMATURE_CLOSE") { - er = null; - } - _destroy(this, er || err); - }); - return; - } - } - - _destroy(this, err || this[kError]); - } else { - //tickOnSocket(this, socket); - //this._flush(); - } + // TODO(bartlomieju): handle error + onSocket(socket, _err) { + nextTick(() => { + this.socket = socket; + this.emit("socket", socket); + }); } // deno-lint-ignore no-explicit-any |