Skip to content

Add local port binding to HTTPClient.Configuration - #914

Open
VictorDebray wants to merge 1 commit into
swift-server:mainfrom
VictorDebray:feat/add-local-port-binding
Open

Add local port binding to HTTPClient.Configuration#914
VictorDebray wants to merge 1 commit into
swift-server:mainfrom
VictorDebray:feat/add-local-port-binding

Conversation

@VictorDebray

Copy link
Copy Markdown

Adds a localPort: Int knob on HTTPClient.Configuration that pins the TCP source port the connection binds to before connecting, plus a per-request HTTPClientRequest.localPort override. 0 (the default) keeps the previous behaviour of letting the OS assign an ephemeral port.

localPort is threaded through RequestOptions and ConnectionPool.Key alongside the existing localAddress, so connections with different (localAddress, localPort) pairs are pooled separately. Both the NIOTS (requiredLocalEndpoint) and NIOPosix (bind(to:)) bootstraps in the plain and TLS paths honour it.

Adds a `localPort: Int` knob on `HTTPClient.Configuration` that pins the TCP
source port the connection binds to before connecting, plus a per-request
`HTTPClientRequest.localPort` override. `0` (the default) keeps the previous
behaviour of letting the OS assign an ephemeral port.

`localPort` is threaded through `RequestOptions` and `ConnectionPool.Key`
alongside the existing `localAddress`, so connections with different
`(localAddress, localPort)` pairs are pooled separately. Both the NIOTS
(`requiredLocalEndpoint`) and NIOPosix (`bind(to:)`) bootstraps in the plain
and TLS paths honour it.
@glbrntt
glbrntt requested a review from fabianfett August 4, 2026 07:03
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

Successfully merging this pull request may close these issues.

1 participant