fix(proxy): handle blocked CONNECT resets

This commit is contained in:
tke
2026-07-01 09:37:41 +02:00
parent f540e08437
commit 52e0c00cd8
+6 -2
View File
@@ -329,6 +329,11 @@ function createBridge(port, profileName) {
const portNum = Number(portStr || 443);
const { config: upstreamConfig, overrideProfile } = getUpstream(profileName, `https://${req.url}/`, host);
const upstream = parseProxyConfig(upstreamConfig);
let upstreamSocket;
clientSocket.on('error', () => {
if (upstreamSocket) upstreamSocket.destroy();
});
log('INFO', id, 'connect', { port, profile: profileName, override: overrideProfile, target: req.url, upstream: upstreamConfig });
@@ -336,7 +341,7 @@ function createBridge(port, profileName) {
return clientSocket.end('HTTP/1.1 403 Forbidden\r\n\r\n');
}
const upstreamSocket = net.connect(upstream.type === 'PROXY' ? upstream.port : portNum, upstream.type === 'PROXY' ? upstream.host : host, () => {
upstreamSocket = net.connect(upstream.type === 'PROXY' ? upstream.port : portNum, upstream.type === 'PROXY' ? upstream.host : host, () => {
if (upstream.type === 'PROXY') {
if (!AUTH_HEADER) refreshAuth();
upstreamSocket.write(`CONNECT ${req.url} HTTP/1.1\r\nHost: ${req.url}\r\n`);
@@ -379,7 +384,6 @@ function createBridge(port, profileName) {
});
}
upstreamSocket.on('error', () => clientSocket.end('HTTP/1.1 502 Bad Gateway\r\n\r\n'));
clientSocket.on('error', () => upstreamSocket.end());
});
server.listen(port, LISTEN_HOST, () => {