Skip to content

fix: allow unsetting default Accept-Encoding header - #1865

Closed
saiyam-jain-dev wants to merge 1 commit into
forwardemail:masterfrom
saiyam-jain-dev:fix/unset-accept-encoding
Closed

saiyam-jain-dev wants to merge 1 commit into
forwardemail:masterfrom
saiyam-jain-dev:fix/unset-accept-encoding

Conversation

@saiyam-jain-dev

Copy link
Copy Markdown

Fixes #1860.

Problem

Calling req.unset('Accept-Encoding') does not prevent Accept-Encoding: gzip, deflate from being sent because Request.prototype.request in src/node/index.js sets the default header unconditionally whenever the method is not HEAD.

In addition, an earlier attempt to address this (#1560) was reverted in v5.3.1 (#1573) because _unset was only initialized in Node and was undefined in browser environments, causing set() to throw.

Fix

  1. Track unset headers in this._unset inside RequestBase.prototype.unset and clear entries on set(), safely guarding when this._unset is undefined.
  2. Initialize this._unset = {} in _initHeaders (src/node/index.js) and in the browser Request constructor (src/client.js) for consistency.
  3. Check !(this._unset && 'accept-encoding' in this._unset) before setting the default Accept-Encoding header in src/node/index.js.

Tests

  • Added tests in test/node/basic.js verifying that req.unset('Accept-Encoding') suppresses the header and that subsequent set() calls restore it.
  • Full test suite (409 passing) and lint passed cleanly.

@titanism titanism closed this in cc24a56 Nov 7, 2026
@titanism titanism mentioned this pull request Nov 7, 2026
6 tasks done
@titanism

titanism commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Thanks. #1861, #1867 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