Skip to content

Commit

Permalink
Properly differintiate http and https proxies
Browse files Browse the repository at this point in the history
options.secureEndpoint is not always defined. There is however, a
function to properly identify the type of connection in the base
class, so intead of rolling the own check, relly on the base class
implementation.

Fixes #87 and npm/cli#7024

Contributed by STMicroelectronics

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
  • Loading branch information
Torbjorn-Svensson committed Jan 31, 2024
1 parent 9ffc694 commit eae4b1c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = class Agent extends AgentBase {

let ProxyAgent = this.#ProxyAgent
if (Array.isArray(ProxyAgent)) {
ProxyAgent = options.secureEndpoint ? ProxyAgent[1] : ProxyAgent[0]
ProxyAgent = this.isSecureEndpoint(options) ? ProxyAgent[1] : ProxyAgent[0]
}

const proxyAgent = new ProxyAgent(proxy, this.#options)
Expand Down Expand Up @@ -106,6 +106,7 @@ module.exports = class Agent extends AgentBase {

let socket
let timeout = this.#timeouts.connection
const isSecureEndpoint = this.isSecureEndpoint(options)

const proxy = this.#getProxy(options)
if (proxy) {
Expand All @@ -124,7 +125,7 @@ module.exports = class Agent extends AgentBase {
timeout = timeout - (Date.now() - start)
}
} else {
socket = (options.secureEndpoint ? tls : net).connect(options)
socket = (isSecureEndpoint ? tls : net).connect(options)
}

socket.setKeepAlive(this.keepAlive, this.keepAliveMsecs)
Expand All @@ -133,8 +134,8 @@ module.exports = class Agent extends AgentBase {
const abortController = new AbortController()
const { signal } = abortController

const connectPromise = socket[options.secureEndpoint ? 'secureConnecting' : 'connecting']
? once(socket, options.secureEndpoint ? 'secureConnect' : 'connect', { signal })
const connectPromise = socket[isSecureEndpoint ? 'secureConnecting' : 'connecting']
? once(socket, isSecureEndpoint ? 'secureConnect' : 'connect', { signal })
: Promise.resolve()

await this.#timeoutConnection({
Expand Down

0 comments on commit eae4b1c

Please sign in to comment.