Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly differentiate http and https proxies #92

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading