Skip to content

Commit

Permalink
avoid inserting extraneous"accept-encoding" header (#5057)
Browse files Browse the repository at this point in the history
* add no extraneous accept-encoding header test

* ensure fetch honors no decompress opt

* fix format on test/js/node/http/node-http.test.ts
  • Loading branch information
iidebyo committed Sep 13, 2023
1 parent 9a0ea00 commit 9101774
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/http_client_async.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 21 additions & 0 deletions test/js/node/http/node-http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 9101774

Please sign in to comment.