summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit_node/http_test.ts16
-rw-r--r--ext/node/polyfills/http.ts11
2 files changed, 18 insertions, 9 deletions
diff --git a/cli/tests/unit_node/http_test.ts b/cli/tests/unit_node/http_test.ts
index c8c2a52a2..adeaf466d 100644
--- a/cli/tests/unit_node/http_test.ts
+++ b/cli/tests/unit_node/http_test.ts
@@ -713,11 +713,17 @@ Deno.test(
"[node/http] client end with callback",
{ permissions: { net: true } },
async () => {
+ let received = false;
+ const ac = new AbortController();
+ const server = Deno.serve({ port: 5928, signal: ac.signal }, (_req) => {
+ received = true;
+ return new Response("hello");
+ });
const promise = deferred();
let body = "";
const request = http.request(
- "http://localhost:4545/http_version",
+ "http://localhost:5928/",
(resp) => {
resp.on("data", (chunk) => {
body += chunk;
@@ -729,10 +735,14 @@ Deno.test(
},
);
request.on("error", promise.reject);
- request.end();
+ request.end(() => {
+ assert(received);
+ });
await promise;
+ ac.abort();
+ await server.finished;
- assertEquals(body, "HTTP/1.1");
+ assertEquals(body, "hello");
},
);
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index 391906c40..17ab8ce31 100644
--- a/ext/node/polyfills/http.ts
+++ b/ext/node/polyfills/http.ts
@@ -629,14 +629,13 @@ class ClientRequest extends OutgoingMessage {
core.tryClose(this._bodyWriteRid);
}
-
- try {
- cb?.();
- } catch (_) {
- //
- }
})(),
]);
+ try {
+ cb?.();
+ } catch (_) {
+ //
+ }
if (this._timeout) {
this._timeout.removeEventListener("abort", this._timeoutCb);
webClearTimeout(this._timeout[timerId]);