Skip to content

Commit 0f31047

Browse files
author
LiudasSmatavicius
authoredMay 12, 2023
Pass localAddress for "request" and "connect" (#166)
1 parent 8224332 commit 0f31047

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
 

‎.changeset/itchy-ravens-leave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"proxy": minor
3+
---
4+
5+
Add `localAddress` option to specify which networking interface the proxy should use to create outgoing connections

‎packages/proxy/src/proxy.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const hostname = os.hostname();
2020

2121
export interface ProxyServer extends http.Server {
2222
authenticate?: (req: http.IncomingMessage) => boolean | Promise<boolean>;
23+
localAddress?: string;
2324
}
2425

2526
/**
@@ -190,15 +191,12 @@ async function onrequest(
190191
return;
191192
}
192193

193-
//if (server.localAddress) {
194-
// parsed.localAddress = server.localAddress;
195-
//}
196-
197194
let gotResponse = false;
198195
const proxyReq = http.request({
199196
...parsed,
200197
method: req.method,
201198
headers,
199+
localAddress: this.localAddress
202200
});
203201
debug.proxyRequest('%s %s HTTP/1.1 ', proxyReq.method, proxyReq.path);
204202

@@ -417,7 +415,8 @@ async function onconnect(
417415
const lastColon = req.url.lastIndexOf(':');
418416
const host = req.url.substring(0, lastColon);
419417
const port = parseInt(req.url.substring(lastColon + 1), 10);
420-
const opts = { host: host.replace(/^\[|\]$/g, ''), port };
418+
const localAddress = this.localAddress
419+
const opts = { host: host.replace(/^\[|\]$/g, ''), port, localAddress };
421420

422421
debug.proxyRequest('connecting to proxy target %o', opts);
423422
const target = net.connect(opts);

1 commit comments

Comments
 (1)

vercel[bot] commented on May 12, 2023

@vercel[bot]
Please sign in to comment.