mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
fix(node/http): call callback after request is sent (#19871)
Fixes #19762
This commit is contained in:
parent
cfb9478a43
commit
bf4e99cbd7
2 changed files with 18 additions and 9 deletions
|
@ -713,11 +713,17 @@ Deno.test(
|
||||||
"[node/http] client end with callback",
|
"[node/http] client end with callback",
|
||||||
{ permissions: { net: true } },
|
{ permissions: { net: true } },
|
||||||
async () => {
|
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();
|
const promise = deferred();
|
||||||
let body = "";
|
let body = "";
|
||||||
|
|
||||||
const request = http.request(
|
const request = http.request(
|
||||||
"http://localhost:4545/http_version",
|
"http://localhost:5928/",
|
||||||
(resp) => {
|
(resp) => {
|
||||||
resp.on("data", (chunk) => {
|
resp.on("data", (chunk) => {
|
||||||
body += chunk;
|
body += chunk;
|
||||||
|
@ -729,10 +735,14 @@ Deno.test(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
request.on("error", promise.reject);
|
request.on("error", promise.reject);
|
||||||
request.end();
|
request.end(() => {
|
||||||
|
assert(received);
|
||||||
|
});
|
||||||
|
|
||||||
await promise;
|
await promise;
|
||||||
|
ac.abort();
|
||||||
|
await server.finished;
|
||||||
|
|
||||||
assertEquals(body, "HTTP/1.1");
|
assertEquals(body, "hello");
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -629,14 +629,13 @@ class ClientRequest extends OutgoingMessage {
|
||||||
|
|
||||||
core.tryClose(this._bodyWriteRid);
|
core.tryClose(this._bodyWriteRid);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
cb?.();
|
|
||||||
} catch (_) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
})(),
|
})(),
|
||||||
]);
|
]);
|
||||||
|
try {
|
||||||
|
cb?.();
|
||||||
|
} catch (_) {
|
||||||
|
//
|
||||||
|
}
|
||||||
if (this._timeout) {
|
if (this._timeout) {
|
||||||
this._timeout.removeEventListener("abort", this._timeoutCb);
|
this._timeout.removeEventListener("abort", this._timeoutCb);
|
||||||
webClearTimeout(this._timeout[timerId]);
|
webClearTimeout(this._timeout[timerId]);
|
||||||
|
|
Loading…
Reference in a new issue