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 9880130d3e7a3..15d174545863b 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 => {