Skip to content

Set localAddress? #184

Description

@vaultjsp

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.

Activity

  1. pimterry commented on Nov 18, 2024

    @pimterry
    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.

  2. vaultjsp commented on Nov 18, 2024

    @vaultjsp
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions