-
Notifications
You must be signed in to change notification settings - Fork 88
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
Comments
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 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 Does that make sense? If you're interested have a look into those details and let me know if you need any pointers. |
Thanks! Using localAddress does in fact work. It turns out I was updating the wrong http agent initially. As a quick and dirty solution, I’m using an environment variable I pass in when I start the program, but I do want to come up with a better solution. I’ll look into your suggestions. Thanks again!
On Nov 18, 2024, at 6:56 AM, Tim Perry ***@***.***> wrote:
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<https://github.com/httptoolkit/mockttp/blob/c894ce1961e37a33e2681594ec92243b6aa82da6/src/rules/passthrough-handling-definitions.ts#L39>), then using it when the request is made (here<https://github.com/httptoolkit/mockttp/blob/c894ce1961e37a33e2681594ec92243b6aa82da6/src/rules/requests/request-handlers.ts#L745>).
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.
—
Reply to this email directly, view it on GitHub<#184 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AIWUBZEPZYWPMKDCK7ZM5BT2BHPZXAVCNFSM6AAAAABR3425S2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBSHE3TGOJYGQ>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
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.
The text was updated successfully, but these errors were encountered: