Skip to content

add proxy-header support - #912

Merged
glbrntt merged 4 commits into
swift-server:mainfrom
benrobby:proxy-connect-headers
Jul 23, 2026
Merged

add proxy-header support#912
glbrntt merged 4 commits into
swift-server:mainfrom
benrobby:proxy-connect-headers

Conversation

@benrobby

Copy link
Copy Markdown
Contributor

Motivation:

when connecting via a HTTP proxy, this now allows users to set HTTP headers on the CONNECT request to the proxy. This is useful for caller attribution purposes.

Modifications:

  • adds a connectHeaders parameter to HTTPClient.Configuration
  • parses connectHeaders swift-configuration property as list of colon-separated key: value pairs
  • sets proxy headers on CONNECT request

Result:
implements proxy-header support

Motivation:

when connecting via HTTP proxy, allow users to set HTTP headers on the CONNECT request to the proxy. This is useful for attribution purposes.

Modifications:
- adds a `connectHeaders` parameter to HTTPClient.Configuration
- parses `connectHeaders` swift-configuration property as list of colon-separated `key: value` pairs
- sets proxy headers on CONNECT request

Result:
implements proxy-header support
@benrobby
benrobby force-pushed the proxy-connect-headers branch from b41c2bc to 777e3ee Compare July 23, 2026 07:22

@glbrntt glbrntt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM module a couple of nits

Comment thread Sources/AsyncHTTPClient/HTTPClient+Proxy.swift Outdated
Comment thread Sources/AsyncHTTPClient/HTTPClient+Proxy.swift
@benrobby
benrobby requested a review from glbrntt July 23, 2026 11:07
Comment thread Sources/AsyncHTTPClient/HTTPClient+Proxy.swift Outdated

@glbrntt glbrntt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice patch, thank you!

@glbrntt glbrntt added the 🆕 semver/minor Adds new public API. label Jul 23, 2026
@glbrntt
glbrntt enabled auto-merge (squash) July 23, 2026 11:50
@glbrntt
glbrntt merged commit 9544287 into swift-server:main Jul 23, 2026
36 checks passed
@benrobby
benrobby deleted the proxy-connect-headers branch July 23, 2026 11:58
o-nnerb added a commit to request-dl/request-dl-nio that referenced this pull request Aug 17, 2026
## Summary
- Adds `connectHeaders` to `Proxy`, exposing async-http-client's
`connectHeaders` (swift-server/async-http-client#912, available since
the pinned `1.36.0`) — extra headers sent only on the HTTP `CONNECT`
request used to establish the proxy tunnel.
- `connectHeaders` is composed as a `Property` builder, the same way
`Form` scopes its own per-part headers: `Proxy` becomes generic over
`Headers: Property`, and a new init resolves that subtree via
`_makeProperty` + `search(for: HeaderNode.self)` into a local
`HTTPHeaders` value, entirely separate from the request's own headers.
- `Internals.Proxy` gains a `connectHeaders` field, threaded only
through the `.http` branch of `build()`. Excluded from `Hashable` —
`NIOHTTP1.HTTPHeaders` isn't `Hashable` — mirroring how
`async-http-client`'s own `Proxy` type handles the same constraint.
- The two existing initializers (`authorization:` and `connection:`) are
unchanged, constrained to `Headers == EmptyProperty`.

```swift
DataTask {
    BaseURL("example.com")
    Proxy(host: "proxy.example.com", port: 8080) {
        CustomHeader(name: "X-Proxy-Token", value: "abc123")
    }
}
```

Marked `breaking-changes` because `Proxy` is now generic
(`Proxy<Headers: Property>`) — source-compatible for every existing call
site, but any code that spells the type explicitly (e.g. `let p: Proxy`)
needs `Proxy<EmptyProperty>`.

Implements #279.

## Test plan
- [x] `swift test --filter RequestDLTests.ProxyTests`
- [x] `swift test --filter RequestDLInternalsTests.InternalsProxyTests`
- [x] `swift test` (full suite, 1103 tests)
- [x] `swift format lint --recursive --strict Sources Tests`

---------

Co-authored-by: brennobemoura <37243584+brennobemoura@users.noreply.github.com>
o-nnerb added a commit to request-dl/request-dl-nio that referenced this pull request Aug 17, 2026
Exposes async-http-client's connectHeaders (swift-server/async-http-client#912,
available since the pinned 1.36.0) through Proxy, composed as a Property builder
the same way Form scopes its own per-part headers — resolves the Headers subtree
via _makeProperty + search(for: HeaderNode.self) into a local HTTPHeaders value
instead of writing into the main request headers.

Internals.Proxy gains a connectHeaders field, threaded only through the .http
branch of build(); excluded from Hashable since NIOHTTP1.HTTPHeaders isn't,
mirroring how async-http-client's own Proxy handles the same constraint.

Implements #279.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants