summaryrefslogtreecommitdiff
path: root/ext/node
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node')
-rw-r--r--ext/node/polyfills/http.ts45
1 files changed, 35 insertions, 10 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index 250d34e7c..697de6414 100644
--- a/ext/node/polyfills/http.ts
+++ b/ext/node/polyfills/http.ts
@@ -267,9 +267,6 @@ 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,7 +541,6 @@ class ClientRequest extends OutgoingMessage {
this.onSocket(createConnection(optsWithoutSignal));
}
}*/
- this.onSocket(new FakeSocket());
const url = this._createUrlStrFromOptions();
@@ -574,12 +570,41 @@ class ClientRequest extends OutgoingMessage {
return undefined;
}
- // TODO(bartlomieju): handle error
- onSocket(socket, _err) {
- nextTick(() => {
- this.socket = socket;
- this.emit("socket", socket);
- });
+ 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();
+ }
}
// deno-lint-ignore no-explicit-any