fix: proxy sometimes not working #1117
Massimo Melina committed
Nov 4, 2025 at 00:00 UTC
49a4c1aca2a3a02385f35244790f0e153d208014
1 file changed
+12
-7
src/util-http.ts
+12
-7
@@ -105,19 +105,24 @@ export function httpStream(url: string, { body, proxy, jar, noRedirect, httpThro
105
106
function connect() {
107
return proxyParsed && new Promise<boolean>(resolve => {
108
- (proxyParsed.protocol === 'https:' ? https : http).request({
108
+ const path = `${parsed.hostname}:${parsed.port || 443}`
109
+ ;(proxyParsed.protocol === 'https:' ? https : http).request({
110
...proxyParsed,
111
+ auth: undefined, // void proxyParsed.auth
112
method: 'CONNECT',
111
- path: `${parsed.hostname}:${parsed.port || 443}`,
112
- auth: undefined,
113
- headers: proxyAuth
114
- }).on('error', reject).on('connect', (res, socket) => {
113
+ path,
114
+ headers: { Host: path, ...proxyAuth }
115
+ }).on('connect', (res, socket) => {
116
if (res.statusCode !== 200)
117
return resolve(false)
117
- // a TLS for every request is inefficient. Consider optimizing in the future, especially for reading plugins from github, which makes tens of requests.
118
+ // we are creating a TLS for every request, very inefficient. Consider optimizing in the future, especially for reading plugins from github, which makes tens of requests.
119
options.createConnection = () => tls.connect({ socket, servername: parsed.hostname || undefined })
120
resolve(true)
120
- }).end()
121
+ }).on('response', res => {
122
+ console.debug("proxy CONNECT response", res.statusCode, res.statusMessage)
123
+ resolve(false)
124
+ }).on('error', reject)
125
+ .end()
126
})
127
}
128