Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit 370bc4a

Browse files
author
warner
committed
further support for HTTP_PROXY env variable
1 parent 800976e commit 370bc4a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

cbt_tunnels.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function cbtSocket(api, params) {
101101
var conn = self.conn = null;
102102

103103
if (process.env.http_proxy || process.env.https_proxy){
104-
var agent = process.env.http_proxy ? new proxyAgent({host:process.env.http_proxy.split(':')[1].replace('//',''),port:process.env.http_proxy.split(':')[2],secureProxy:true}) : new proxyAgent({host:process.env.https_proxy.split(':')[1].replace('//',''),port:process.env.https_proxy.split(':')[2],secureProxy:true});
104+
var agent = makeProxyAgent();
105105
conn = self.conn = new WebSocket(self.wsPath,{agent: agent});
106106
}else{
107107
conn = self.conn = new WebSocket(self.wsPath,{});
@@ -681,6 +681,19 @@ function cbtSocket(api, params) {
681681
&& (Object.getOwnPropertyNames(connection_list[id].client.address()).length > 0)
682682
)
683683
}
684+
685+
function makeProxyAgent(){
686+
var pString = process.env.http_proxy || process.env.https_proxy;
687+
pString = pString.replace('http://','');
688+
var agentAuth;
689+
if(pString.includes('@')){
690+
agentAuth = pString.slice(0,pString.indexOf('@'));
691+
}
692+
var agentHost = pString.slice(pString.indexOf('@')+1,pString.lastIndexOf(':'));
693+
var agentPort = pString.slice(pString.lastIndexOf(':')+1);
694+
var agent = new proxyAgent({host:agentHost,port:agentPort,auth:agentAuth,secureProxy:true});
695+
return agent;
696+
}
684697
}
685698

686699
module.exports = cbtSocket;

0 commit comments

Comments
 (0)