You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can provide custom HTTP/HTTPS agents to enable connection pooling and reuse with upstream proxies. This is particularly useful for maintaining sticky IP addresses or reducing connection overhead:
116
+
117
+
```javascript
118
+
consthttp=require('http');
119
+
consthttps=require('https');
120
+
constProxyChain=require('proxy-chain');
121
+
122
+
// Create agents with keepAlive to enable connection pooling
123
+
consthttpAgent=newhttp.Agent({
124
+
keepAlive:true,
125
+
maxSockets:10,
126
+
});
127
+
128
+
consthttpsAgent=newhttps.Agent({
129
+
keepAlive:true,
130
+
maxSockets:10,
131
+
});
132
+
133
+
constserver=newProxyChain.Server({
134
+
port:8000,
135
+
prepareRequestFunction: ({ request }) => {
136
+
return {
137
+
upstreamProxyUrl:'http://proxy.example.com:8080',
138
+
// Or for HTTPS upstream proxy: 'https://proxy.example.com:8080'
139
+
140
+
// Agents enable connection pooling to upstream proxy
141
+
httpAgent, // Used for HTTP upstream proxies
142
+
httpsAgent, // Used for HTTPS upstream proxies
143
+
};
144
+
},
145
+
});
146
+
147
+
server.listen(() => {
148
+
console.log(`Proxy server is listening on port ${server.port}`);
149
+
});
150
+
```
151
+
152
+
**Note:** Custom agents are only supported for HTTP and HTTPS upstream proxies. SOCKS upstream proxies use direct socket connections and do not support custom agents.
153
+
113
154
## SOCKS support
114
155
SOCKS protocol is supported for versions 4 and 5, specifically: `['socks', 'socks4', 'socks4a', 'socks5', 'socks5h']`, where `socks` will default to version 5.
Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "proxy-chain",
3
-
"version": "2.5.9",
3
+
"version": "2.6.0",
4
4
"description": "Node.js implementation of a proxy server (think Squid) with support for SSL, authentication, upstream proxy chaining, and protocol tunneling.",
0 commit comments