1
0
Fork 0
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:
Marvin Hagemeister 2024-07-10 10:05:41 +02:00 committed by GitHub
parent 92d567d356
commit 2a86edf0af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View file

@ -322,6 +322,7 @@ class ClientRequest extends OutgoingMessage {
insecureHTTPParser: boolean;
useChunkedEncodingByDefault: boolean;
path: string;
_req: { requestRid: number; cancelHandleRid: number | null } | undefined;
constructor(
input: string | URL,
@ -819,7 +820,9 @@ class ClientRequest extends OutgoingMessage {
if (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);
}
// If we're aborting, we don't care about any more response data.

View file

@ -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 () => {
const http = await import("node:http");
assert(