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
Bind outbound connections to a local address/interface via local_addr (#834) (#1307)
* Bind outbound connections to a local address/interface via local_addr (#834)
Adds a `local_addr` keyword to `Transport` and `Client` that binds outbound
connections to a specific source IP — and therefore the outgoing interface —
mirroring Go's `net.Dialer.LocalAddr` (and `curl --interface`). Useful on
multi-homed hosts and for separating traffic by interface.
Reseau's HostResolver/TCP.connect already accept a local bind endpoint; this
threads it through HTTP's transport. `local_addr` is a connection-pool
property (each bound Client keeps its own pool), so it lives on the
Transport's resolver — no pool-key changes and no cross-binding reuse, which
is also why it is set per-Transport/Client rather than per-request (matching
Go, where LocalAddr is a Dialer property, not a per-request option).
Accepts an IP-literal String (kernel-chosen ephemeral source port) or a
Reseau TCP.SocketAddrV4/SocketAddrV6 for a fixed source port; interface names
are not accepted (resolve to an IP first, as Go does). Binding to an address
not assigned locally fails fast at bind(). Passing local_addr alongside an
explicit transport is rejected as ambiguous.
Tests cover the normalizer, client- and transport-level binding, the
ambiguity guard, and that an unassigned source address fails (proving the
bind is actually applied). Documents the knob in the client guide.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Collapse _normalize_local_addr into a single method (review feedback)
Keep the local_addr normalization in one method with early-return isa
checks instead of four dispatched methods, so inference does not have to
pick between them.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
0 commit comments