diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 39d2b50a60..edb8dcca4b 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -15,7 +15,7 @@ import { TextEncoder } from "ext:deno_web/08_text_encoding.js"; import { setTimeout } from "ext:deno_web/02_timers.js"; import { _normalizeArgs, - createConnection as netCreateConnection, + createConnection, ListenOptions, Socket, } from "node:net"; @@ -414,7 +414,7 @@ class ClientRequest extends OutgoingMessage { } } else { debug("CLIENT use net.createConnection", optsWithoutSignal); - this.onSocket(netCreateConnection(optsWithoutSignal)); + this.onSocket(createConnection(optsWithoutSignal)); } } } @@ -641,12 +641,13 @@ class ClientRequest extends OutgoingMessage { if (chunk) { this.write_(chunk, encoding, null, true); } else if (!this._headerSent) { - if (this.socket && !this.socket.connecting) { + if ( + (this.socket && !this.socket.connecting) || // socket is not connecting, or + (!this.socket && this.outputData.length === 0) // no data to send + ) { this._contentLength = 0; this._implicitHeader(); this._send("", "latin1"); - } else { - // } } if (this.socket && this._bodyWriter) { @@ -696,6 +697,7 @@ class ClientRequest extends OutgoingMessage { } this.aborted = true; this.emit("abort"); + //process.nextTick(emitAbortNT, this); this.destroy(); } diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts index 091fa7a54a..9da33b532d 100644 --- a/tests/unit_node/http_test.ts +++ b/tests/unit_node/http_test.ts @@ -665,9 +665,7 @@ Deno.test("[node/http] server unref", async () => { assertEquals(statusCode, 0); }); -Deno.test("[node/http] ClientRequest handle non-string headers", { - ignore: true, -}, async () => { +Deno.test("[node/http] ClientRequest handle non-string headers", async () => { // deno-lint-ignore no-explicit-any let headers: any; const { promise, resolve, reject } = Promise.withResolvers(); @@ -709,7 +707,6 @@ Deno.test("[node/http] ClientRequest uses HTTP/1.1", { req.once("error", (e) => reject(e)); req.end(); await promise; - console.log(body); assertEquals(body, "HTTP/1.1"); });