Skip to content

Commit

Permalink
fix: use current agent to determine secure proxy
Browse files Browse the repository at this point in the history
This matches the old behavior of `make-fetch-happen@11.1.1`[1] where the
proxy agent was determined based on the original request url.

Fixes npm/cli#6760

[1]: https://github.com/npm/make-fetch-happen/blob/eb4a83806e9deb7e441c8f2f6a673f929055a5eb/lib/agent.js#L195C1-L195C1
  • Loading branch information
lukekarrys authored and wraithgar committed Sep 8, 2023
1 parent 4b2c4d1 commit 9937e66
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
8 changes: 3 additions & 5 deletions lib/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const tls = require('tls')
const { once } = require('events')
const { createTimeout, abortRace, urlify, appendPort, cacheAgent } = require('./util')
const { normalizeOptions, cacheOptions } = require('./options')
const { getProxy, getProxyType, isSecureProxy, proxyCache } = require('./proxy.js')
const { getProxy, getProxyType, proxyCache } = require('./proxy.js')
const Errors = require('./errors.js')

const createAgent = (base, name) => {
Expand Down Expand Up @@ -43,18 +43,16 @@ const createAgent = (base, name) => {
return
}

const secure = isSecureProxy(proxy)

return cacheAgent({
key: cacheOptions({
...options,
...this.#options,
secure,
secure: SECURE,
timeouts: this.#timeouts,
proxy,
}),
cache: proxyCache,
secure,
secure: SECURE,
proxies: this.#proxy.proxies,
}, proxy, this.#options)
}
Expand Down
8 changes: 0 additions & 8 deletions lib/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ const PROXY_ENV = (() => {
})()

const SOCKS_PROTOCOLS = new Set(SocksProxyAgent.protocols)
const SECURE_PROTOCOLS = new Set([...SocksProxyAgent.protocols, 'https'])

const isSecureProxy = (url) => {
url = urlify(url)
const protocol = url.protocol.slice(0, -1)
return SECURE_PROTOCOLS.has(protocol)
}

const getProxyType = (url) => {
url = urlify(url)
Expand Down Expand Up @@ -91,6 +84,5 @@ const getProxy = (url, {
module.exports = {
getProxyType,
getProxy,
isSecureProxy,
proxyCache: PROXY_CACHE,
}

0 comments on commit 9937e66

Please sign in to comment.