fix: don't put opts.headers into the agent itself #105
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR came about as I was looking into an error message complained by
npm install
using a http proxy. The headercontent-encoding: gzip
was sent in a fetch tohttps://registry.npmmirror.com/tar/-/tar-6.2.1.tgz
, causing a 400 Bad Request response, but it's not the case when no http proxy was set; the install simply succeeded.A minimal reproduction:
Digging into the code I found that the request to
https://registry.npmmirror.com/*/-/*-<version>.tgz
was never meant to be usinggzip: true
, nor had thecontent-encoding: gzip
header ever been passed inopts.header
field. It's theagent
, that (unnecessarily and unwantedly?) contained thecontent-encoding: gzip
header passed from the first request (which was the one meant to be using gzipped request body), and reused by caching mechanism for following requests. However,agent.headers
will be picked up if and only if an http proxy is configured:agent/lib/agents.js
Line 175 in 21c1987
The most obvious fix seems to be removing
headers
field inagent
'snormalizeOptions
; an agent is not expected to remember the headers, in usual sense. I don't know the fix is good enough to be approved; it may bring unexpected implications or break some existing usages, since my situation is only a rather marginal case.References
None