diff options
author | osddeitf <37999210+osddeitf@users.noreply.github.com> | 2023-08-28 14:32:54 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-28 09:32:54 +0200 |
commit | c2547ba039096d2f8e07a2fd89360956ac94014a (patch) | |
tree | 0b08421954e4a618ce5d59f08f81f27dc112579e /ext/node/polyfills/http.ts | |
parent | d22a6663fa0349acb6a68c53fdcbfac0426555d2 (diff) |
fix(node/http): correctly send `Content-length` header instead of `Transfer-Encoding: chunked` (#20127)
Fix #20063.
Diffstat (limited to 'ext/node/polyfills/http.ts')
-rw-r--r-- | ext/node/polyfills/http.ts | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 52aac4cae..1103e93c3 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -566,7 +566,9 @@ class ClientRequest extends OutgoingMessage { } }*/ this.onSocket(new FakeSocket({ encrypted: this._encrypted })); + } + _writeHeader() { const url = this._createUrlStrFromOptions(); const headers = []; @@ -585,12 +587,22 @@ class ClientRequest extends OutgoingMessage { url, headers, client.rid, - this.method === "POST" || this.method === "PATCH" || - this.method === "PUT", + (this.method === "POST" || this.method === "PATCH" || + this.method === "PUT") && this._contentLength !== 0, ); this._bodyWriteRid = this._req.requestBodyRid; } + _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; } @@ -615,8 +627,12 @@ class ClientRequest extends OutgoingMessage { } this.finished = true; - if (chunk !== undefined && chunk !== null) { - this.write(chunk, encoding); + if (chunk) { + this.write_(chunk, encoding, null, true); + } else if (!this._headerSent) { + this._contentLength = 0; + this._implicitHeader(); + this._send("", "latin1"); } (async () => { |