mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 20:25:12 -05: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;
|
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
|
// deno-lint-ignore no-explicit-any
|
||||||
end(chunk?: any, encoding?: any, cb?: any): this {
|
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;
|
this.finished = true;
|
||||||
if (chunk !== undefined && chunk !== null) {
|
if (chunk !== undefined && chunk !== null) {
|
||||||
this.write(chunk, encoding);
|
this.write(chunk, encoding);
|
||||||
|
@ -617,12 +626,12 @@ class ClientRequest extends OutgoingMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
core.tryClose(this._bodyWriteRid);
|
core.tryClose(this._bodyWriteRid);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cb?.();
|
cb?.();
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
//
|
//
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
]);
|
]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue