mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
chore(ext/node): bring back changes to ClientRequest.onSocket (#19509)
Reverts denoland/deno#19426
This commit is contained in:
parent
e05cc74750
commit
cde9e99c7d
2 changed files with 16 additions and 37 deletions
|
@ -196,11 +196,14 @@ Deno.test("[node/http] request default protocol", async () => {
|
||||||
// @ts-ignore IncomingMessageForClient
|
// @ts-ignore IncomingMessageForClient
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
let clientRes: any;
|
let clientRes: any;
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
let clientReq: any;
|
||||||
server.listen(() => {
|
server.listen(() => {
|
||||||
const req = http.request(
|
clientReq = http.request(
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
{ host: "localhost", port: (server.address() as any).port },
|
{ host: "localhost", port: (server.address() as any).port },
|
||||||
(res) => {
|
(res) => {
|
||||||
|
assert(res.socket instanceof EventEmitter);
|
||||||
assertEquals(res.complete, false);
|
assertEquals(res.complete, false);
|
||||||
res.on("data", () => {});
|
res.on("data", () => {});
|
||||||
res.on("end", () => {
|
res.on("end", () => {
|
||||||
|
@ -211,13 +214,14 @@ Deno.test("[node/http] request default protocol", async () => {
|
||||||
promise2.resolve();
|
promise2.resolve();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
req.end();
|
clientReq.end();
|
||||||
});
|
});
|
||||||
server.on("close", () => {
|
server.on("close", () => {
|
||||||
promise.resolve();
|
promise.resolve();
|
||||||
});
|
});
|
||||||
await promise;
|
await promise;
|
||||||
await promise2;
|
await promise2;
|
||||||
|
assert(clientReq.socket instanceof EventEmitter);
|
||||||
assertEquals(clientRes!.complete, true);
|
assertEquals(clientRes!.complete, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -270,6 +270,9 @@ const kError = Symbol("kError");
|
||||||
|
|
||||||
const kUniqueHeaders = Symbol("kUniqueHeaders");
|
const kUniqueHeaders = Symbol("kUniqueHeaders");
|
||||||
|
|
||||||
|
class FakeSocket extends EventEmitter {
|
||||||
|
}
|
||||||
|
|
||||||
/** ClientRequest represents the http(s) request from the client */
|
/** ClientRequest represents the http(s) request from the client */
|
||||||
class ClientRequest extends OutgoingMessage {
|
class ClientRequest extends OutgoingMessage {
|
||||||
defaultProtocol = "http:";
|
defaultProtocol = "http:";
|
||||||
|
@ -544,6 +547,7 @@ class ClientRequest extends OutgoingMessage {
|
||||||
this.onSocket(createConnection(optsWithoutSignal));
|
this.onSocket(createConnection(optsWithoutSignal));
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
this.onSocket(new FakeSocket());
|
||||||
|
|
||||||
const url = this._createUrlStrFromOptions();
|
const url = this._createUrlStrFromOptions();
|
||||||
|
|
||||||
|
@ -573,41 +577,12 @@ class ClientRequest extends OutgoingMessage {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
onSocket(socket, err) {
|
// TODO(bartlomieju): handle error
|
||||||
if (this.destroyed || err) {
|
onSocket(socket, _err) {
|
||||||
this.destroyed = true;
|
nextTick(() => {
|
||||||
|
this.socket = socket;
|
||||||
// deno-lint-ignore no-inner-declarations
|
this.emit("socket", socket);
|
||||||
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
|
// deno-lint-ignore no-explicit-any
|
||||||
|
|
Loading…
Reference in a new issue