mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(node/http): don't error if request destroyed before send (#24497)
A request can be destroyed before it was even made in the Node http API. We errored on that. This issue was discovered in the JSDOM test suite.
This commit is contained in:
parent
92d567d356
commit
2a86edf0af
2 changed files with 13 additions and 1 deletions
|
@ -322,6 +322,7 @@ class ClientRequest extends OutgoingMessage {
|
||||||
insecureHTTPParser: boolean;
|
insecureHTTPParser: boolean;
|
||||||
useChunkedEncodingByDefault: boolean;
|
useChunkedEncodingByDefault: boolean;
|
||||||
path: string;
|
path: string;
|
||||||
|
_req: { requestRid: number; cancelHandleRid: number | null } | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
input: string | URL,
|
input: string | URL,
|
||||||
|
@ -819,7 +820,9 @@ class ClientRequest extends OutgoingMessage {
|
||||||
if (rid) {
|
if (rid) {
|
||||||
core.tryClose(rid);
|
core.tryClose(rid);
|
||||||
}
|
}
|
||||||
if (this._req.cancelHandleRid !== null) {
|
|
||||||
|
// Request might be closed before we actually made it
|
||||||
|
if (this._req !== undefined && this._req.cancelHandleRid !== null) {
|
||||||
core.tryClose(this._req.cancelHandleRid);
|
core.tryClose(this._req.cancelHandleRid);
|
||||||
}
|
}
|
||||||
// If we're aborting, we don't care about any more response data.
|
// If we're aborting, we don't care about any more response data.
|
||||||
|
|
|
@ -994,6 +994,15 @@ Deno.test(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Deno.test(
|
||||||
|
"[node/http] client destroy before sending request should not error",
|
||||||
|
() => {
|
||||||
|
const request = http.request("http://localhost:5929/");
|
||||||
|
// Calling this would throw
|
||||||
|
request.destroy();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
Deno.test("[node/http] node:http exports globalAgent", async () => {
|
Deno.test("[node/http] node:http exports globalAgent", async () => {
|
||||||
const http = await import("node:http");
|
const http = await import("node:http");
|
||||||
assert(
|
assert(
|
||||||
|
|
Loading…
Reference in a new issue