summaryrefslogtreecommitdiff
path: root/ext/node
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2024-07-03 19:00:39 +0530
committerGitHub <noreply@github.com>2024-07-03 19:00:39 +0530
commit496ea5903bbe8e86185c30fc6f478b0092d64d65 (patch)
tree12fa4b4057f51fa9cea3218f24df2305642302f5 /ext/node
parentdadc606419096325ef0b03b6216ee20bef442045 (diff)
fix(ext/node): don't wait for end() call to send http client request (#24390)
Closes https://github.com/denoland/deno/issues/24232 Closes https://github.com/denoland/deno/issues/24215
Diffstat (limited to 'ext/node')
-rw-r--r--ext/node/polyfills/http.ts107
1 files changed, 58 insertions, 49 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts
index 6880f7cb8..b1a536113 100644
--- a/ext/node/polyfills/http.ts
+++ b/ext/node/polyfills/http.ts
@@ -623,50 +623,6 @@ class ClientRequest extends OutgoingMessage {
client[internalRidSymbol],
this._bodyWriteRid,
);
- }
-
- _implicitHeader() {
- if (this._header) {
- throw new ERR_HTTP_HEADERS_SENT("render");
- }
- this._storeHeader(
- this.method + " " + this.path + " HTTP/1.1\r\n",
- this[kOutHeaders],
- );
- }
-
- _getClient(): Deno.HttpClient | undefined {
- return undefined;
- }
-
- // TODO(bartlomieju): handle error
- onSocket(socket, _err) {
- nextTick(() => {
- this.socket = socket;
- this.emit("socket", socket);
- });
- }
-
- // 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) {
- this.write_(chunk, encoding, null, true);
- } else if (!this._headerSent) {
- this._contentLength = 0;
- this._implicitHeader();
- this._send("", "latin1");
- }
- this._bodyWriter?.close();
(async () => {
try {
@@ -674,11 +630,6 @@ class ClientRequest extends OutgoingMessage {
if (this._req.cancelHandleRid !== null) {
core.tryClose(this._req.cancelHandleRid);
}
- try {
- cb?.();
- } catch (_) {
- //
- }
if (this._timeout) {
this._timeout.removeEventListener("abort", this._timeoutCb);
webClearTimeout(this._timeout[timerId]);
@@ -788,6 +739,64 @@ class ClientRequest extends OutgoingMessage {
})();
}
+ _implicitHeader() {
+ if (this._header) {
+ throw new ERR_HTTP_HEADERS_SENT("render");
+ }
+ this._storeHeader(
+ this.method + " " + this.path + " HTTP/1.1\r\n",
+ this[kOutHeaders],
+ );
+ }
+
+ _getClient(): Deno.HttpClient | undefined {
+ return undefined;
+ }
+
+ // TODO(bartlomieju): handle error
+ onSocket(socket, _err) {
+ nextTick(() => {
+ this.socket = socket;
+ this.emit("socket", socket);
+ });
+ }
+
+ // 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) {
+ this.write_(chunk, encoding, null, true);
+ } else if (!this._headerSent) {
+ this._contentLength = 0;
+ this._implicitHeader();
+ this._send("", "latin1");
+ }
+ (async () => {
+ try {
+ await this._bodyWriter?.close();
+ } catch (_) {
+ // The readable stream resource is dropped right after
+ // read is complete closing the writable stream resource.
+ // If we try to close the writer again, it will result in an
+ // error which we can safely ignore.
+ }
+ try {
+ cb?.();
+ } catch (_) {
+ //
+ }
+ })();
+ }
+
abort() {
if (this.aborted) {
return;