Skip to content

fix: allow unsetting Accept-Encoding header - #1867

Closed
Rohan-Dedhia wants to merge 1 commit into
forwardemail:masterfrom
Rohan-Dedhia:fix/unset-accept-encoding
Closed

Rohan-Dedhia wants to merge 1 commit into
forwardemail:masterfrom
Rohan-Dedhia:fix/unset-accept-encoding

Conversation

@Rohan-Dedhia

Copy link
Copy Markdown

Description

Fixes #1860.

Currently, calling req.unset('Accept-Encoding') removes 'accept-encoding' from this.header, but src/node/index.js still unconditionally sets req.setHeader('Accept-Encoding', 'gzip, deflate') during request construction for non-HEAD requests.

This change:

  1. Tracks unset header names in this._unset inside RequestBase.prototype.unset (cleared when .set() is called for that field).
  2. Initializes _unset = {} in both client and node request constructors to prevent undefined errors.
  3. Skips default 'gzip, deflate' assignment in src/node/index.js when accept-encoding has been unset.
  4. Adds a regression test in test/node/basic.js asserting that req.unset('Accept-Encoding') does not send an Accept-Encoding header.

@titanism

titanism commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Thanks. #1861, #1865 and this PR took the same approach, and the combined commit credits #1861 as the first. Compared with them, it creates the unset record only when unset() is called, keeps the header unset after redirects, and removes headers regardless of capitalization. Closing in favor of that commit, released in v10.4.2 and now available on npm: https://github.com/forwardemail/superagent/releases/tag/v10.4.2

Consider supporting our efforts to maintain this project by using Forward Email for your email infrastructure needs at https://forwardemail.net.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[fix] Cannot unset Accept-Encoding

2 participants