From 9101774593288e32c7d9f0c77ab6f133628ebd10 Mon Sep 17 00:00:00 2001 From: iidebyo <8409882+iidebyo@users.noreply.github.com> Date: Wed, 13 Sep 2023 05:02:25 -0400 Subject: [PATCH] avoid inserting extraneous"accept-encoding" header (#5057) * add no extraneous accept-encoding header test * ensure fetch honors no decompress opt * fix format on test/js/node/http/node-http.test.ts --- src/http_client_async.zig | 2 +- test/js/node/http/node-http.test.ts | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/http_client_async.zig b/src/http_client_async.zig index f0647421955b9..79fe748997b38 100644 --- a/src/http_client_async.zig +++ b/src/http_client_async.zig @@ -2122,7 +2122,7 @@ pub fn buildRequest(this: *HTTPClient, body_len: usize) picohttp.Request { header_count += 1; } - if (!override_accept_encoding) { + if (!override_accept_encoding and !this.disable_decompression) { request_headers_buf[header_count] = accept_encoding_header; header_count += 1; } diff --git a/test/js/node/http/node-http.test.ts b/test/js/node/http/node-http.test.ts index f80a6c631a5d8..b8302c1d88de7 100644 --- a/test/js/node/http/node-http.test.ts +++ b/test/js/node/http/node-http.test.ts @@ -241,6 +241,27 @@ describe("node:http", () => { // }); // }); + it("should not insert extraneous accept-encoding header", async done => { + try { + let headers; + var server = createServer((req, res) => { + headers = req.headers; + req.on("data", () => {}); + req.on("end", () => { + res.end(); + }); + }); + const url = await listen(server); + await fetch(url, { decompress: false }); + expect(headers["accept-encoding"]).toBeFalsy(); + done(); + } catch (e) { + done(e); + } finally { + server.close(); + } + }); + it("should make a standard GET request when passed string as first arg", done => { runTest(done, (server, port, done) => { const req = request(`http://localhost:${port}`, res => {