Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set localAddress? #184

Open
vaultjsp opened this issue Nov 15, 2024 · 2 comments
Open

Set localAddress? #184

vaultjsp opened this issue Nov 15, 2024 · 2 comments

Comments

@vaultjsp
Copy link

Is it possible to set the localAddress property on the http agent? I have multiple ethernet interfaces and need requests to use a particular interface. So far my attempts have been unsuccessful; tried modifying buildProxyAgent but that didn't seem to work.

@pimterry
Copy link
Member

For the upstream requests you mean? Not currently, no.

I'd be open for a PR for this though. I think this could be more general than proxy configuration - it's perfectly valid to configure the outbound interface for non-proxied traffic too.

Given that, I think this would be a new optional parameter for the passthrough rule. Internally Node.js supports this with the localAddress parameter on connections (I've never tried this myself, but should work for HTTP requests just fine) and we could just use the exact same thing in our API, and pass it right through.

That means adding it to the passthrough connection options (here), then using it when the request is made (here).

This will need tests somewhere, but that should be possible by setting up a raw socket server, connecting to 127.0.0.1 from a different local interface, and then just checking socket.remoteAddress on the resulting connection. There will be some plumbing required - I'd suggest starting with the test, and then working through the changes to get the option into the right place in the code and then get everything working & passing.

Does that make sense? If you're interested have a look into those details and let me know if you need any pointers.

@vaultjsp
Copy link
Author

vaultjsp commented Nov 18, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants