mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04:00
fix(node/http): allow callback in first argument of end call (#19778)
Closes #19762
This commit is contained in:
parent
be9e73d340
commit
4cfc54931d
2 changed files with 42 additions and 5 deletions
|
@ -707,3 +707,31 @@ Deno.test(
|
|||
await promise;
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
"[node/http] client end with callback",
|
||||
{ permissions: { net: true } },
|
||||
async () => {
|
||||
const promise = deferred();
|
||||
let body = "";
|
||||
|
||||
const request = http.request(
|
||||
"http://localhost:4545/http_version",
|
||||
(resp) => {
|
||||
resp.on("data", (chunk) => {
|
||||
body += chunk;
|
||||
});
|
||||
|
||||
resp.on("end", () => {
|
||||
promise.resolve();
|
||||
});
|
||||
},
|
||||
);
|
||||
request.on("error", promise.reject);
|
||||
request.end();
|
||||
|
||||
await promise;
|
||||
|
||||
assertEquals(body, "HTTP/1.1");
|
||||
},
|
||||
);
|
||||
|
|
|
@ -599,6 +599,15 @@ class ClientRequest extends OutgoingMessage {
|
|||
|
||||
// deno-lint-ignore no-explicit-any
|
||||
end(chunk?: any, encoding?: any, cb?: any): this {
|
||||
if (typeof chunk === "function") {
|
||||
cb = chunk;
|
||||
chunk = null;
|
||||
encoding = null;
|
||||
} else if (typeof encoding === "function") {
|
||||
cb = encoding;
|
||||
encoding = null;
|
||||
}
|
||||
|
||||
this.finished = true;
|
||||
if (chunk !== undefined && chunk !== null) {
|
||||
this.write(chunk, encoding);
|
||||
|
@ -617,13 +626,13 @@ class ClientRequest extends OutgoingMessage {
|
|||
}
|
||||
|
||||
core.tryClose(this._bodyWriteRid);
|
||||
}
|
||||
|
||||
try {
|
||||
cb?.();
|
||||
} catch (_) {
|
||||
//
|
||||
}
|
||||
}
|
||||
})(),
|
||||
]);
|
||||
if (this._timeout) {
|
||||
|
|
Loading…
Reference in a new issue