Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
Overview
I’ve noticed a behavior change in npm/agent v2.2.0 that shipped as part of npm/cli v10.2.0.
npm install
appears to always use HttpProxyAgent
instead of selecting between HttpProxyAgent
and HttpsProxyAgent
depending on the requested URL's protocol.
Observations
I think I've isolated the behavior change to #59.
Prior to #59, it looks like the library would select an HttpAgent
or HttpsAgent
based on the url.protocol
of the request.
Lines 20 to 30 in 22ac4e5
Lines 67 to 75 in 22ac4e5
After #59, the library selects an HttpProxyAgent
or HttpsProxyAgent
based on an options.secureEndpoint
property, but this appears to (always?) be undefined and not based on the url.protocol
of the request.
Lines 26 to 36 in e24eb6c
Lines 26 to 32 in e24eb6c
Lines 26 to 37 in e24eb6c
Lines 64 to 72 in e24eb6c
Expected Behavior
- I would expect
npm install
to useHttpProxyAgent
when the requested url has anhttp
protocol. - I would expect
npm install
to useHttpsProxyAgent
when the requested url has anhttps
protocol.
Steps To Reproduce
- Use the latest node and npm, for example:
node v21.3.0 (npm v10.2.4)
- Configure
.npmrc
to use a proxy, for example:
https-proxy=<some proxy>
http-proxy=<some proxy>
- Ensure an empty cache and install a package like
uuid
$ npm cache clean --force
$ npm install -g uuid
- Observe
HttpProxyAgent
is used to fetch anhttps
url:'https://registry.npmjs.org/uuid'
- Observe the
request
'spath
is modified when using anHttpProxyAgent
tosetRequestProps
for anhttps
url. For example, therequest.path
is modified from'/uuid'
to'http://registry.npmjs.org:443/uuid'
.
Lines 161 to 173 in e24eb6c
- Note that the installation succeeds in the example above, but other registries appear to be less forgiving of the path change and this can cause installation issues in some cases.
Environment
- npm: 10.2.4
- Node: 21.3.0
- OS: macOS 14.1.1
- platform: macOS