transfer origin and proxy handling#21967
Closed
icing wants to merge 1 commit into
Closed
Conversation
Add `data->state.origin` as the origin the transfer is sending the current request to/gets the response from. Use it for request specific properties like authentication, hsts and cookie handling, etc. Unless talking to a forwarding HTTP proxy (e.g. not tunneling), `data->state.origin` and `conn->origin` are the same. With a forwarding HTTP proxy in play, `conn->origin` is set to `conn->http_proxy.peer` and `conn->bits.origin_is_proxy` (a new bit) is set. Remove the connection bits, now replaced with: * `conn->bits.socksproxy` -> `conn->socks_proy.peer` * `conn->bits.httpproxy` -> `conn->http_proy.peer` * `conn->bits.proxy` -> `(conn->socks_proy.peer || conn->http_proy.peer`) * `conn->bits.tunnel_proxy` -> (`conn->http_proy.peer && !conn->bits.origin_is_proxy`) * `(conn->bits.httpproxy && !conn->bits.tunnel_proxy)` -> `conn->bits.origin_is_proxy` Rename `noproxy.[ch]` to `proxy.[ch]`. Move the connection proxy setup code from `url.c` to `proxy.c`. Remove `data->info.conn_remote_port` as no one uses it. Add test_40_02b for a SOCKS connection to a forwarding HTTPS proxy. Update internal documentation about peers and creds.
bagder
approved these changes
Jun 12, 2026
There was a problem hiding this comment.
Pull request overview
This PR refactors how libcurl models “where a request is going” vs “where a connection is established” by introducing data->state.origin (per-request origin) and reworking proxy handling so forwarding HTTP proxies become the connection origin while still preserving the transfer origin for request-scoped logic (auth, HSTS, cookies, etc.).
Changes:
- Add
data->state.originand update request-scoped features (auth/SPN, HSTS upgrades, cookies, alt-svc, AWS SigV4, etc.) to use it instead ofconn->origin. - Consolidate proxy configuration/NO_PROXY parsing into new
lib/proxy.[ch], replacing severalconn->bits.*proxy*flags withconn->(socks|http)_proxy.peerandconn->bits.origin_is_proxy. - Add
Curl_conn_is_tunneling()and expand tests/docs, including a new SOCKS→forwarding HTTPS-proxy test.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/unit1614.c | Switch unit test to include proxy.h and call proxy_check_noproxy(). |
| tests/http/test_40_socks.py | Add test coverage for SOCKS to forwarding HTTPS proxy (no tunnel). |
| lib/vquic/vquic.c | Update SOCKS proxy detection to use conn->socks_proxy.peer. |
| lib/vauth/vauth.c | Use data->state.origin when deciding if auth is allowed to the current host. |
| lib/vauth/digest.c | Build SPN from data->state.origin->hostname. |
| lib/vauth/digest_sspi.c | Build SPN from data->state.origin->hostname (SSPI). |
| lib/urldata.h | Add data->state.origin, remove legacy proxy bits, move proxy_info to proxy.h. |
| lib/url.c | Introduce url_set_data_origin_and_creds(), refactor connection/needle setup around data->state.origin, and integrate Curl_proxy_init_conn(). |
| lib/transfer.c | Clear data->state.origin at pretransfer start. |
| lib/proxy.h | New internal proxy API/types/macros and Curl_proxy_init_conn() declaration. |
| lib/proxy.c | New consolidated proxy/no_proxy parsing + connection proxy initialization logic. |
| lib/peer.c | Replace IS_HTTPS_PROXY() with CURL_PROXY_IS_HTTPS(). |
| lib/noproxy.c | Remove old no_proxy implementation (superseded by proxy.c). |
| lib/Makefile.inc | Swap noproxy.[ch] for proxy.[ch] in build lists. |
| lib/http2.c | Use data->state.origin for authority checks; treat forwarding proxy via origin_is_proxy. |
| lib/http.c | Rebase proxy/auth/host/cookie/HSTS/alt-svc behaviors onto data->state.origin + origin_is_proxy. |
| lib/http_proxy.h | Remove IS_HTTPS_PROXY/IS_QUIC_PROXY macros (moved/replaced). |
| lib/http_proxy.c | Use origin_is_proxy to select proxy vs server header behavior. |
| lib/http_ntlm.c | Use data->state.origin->hostname for NTLM host calculations. |
| lib/http_negotiate.c | Use data->state.origin->hostname for negotiate host calculations. |
| lib/http_digest.c | Use data->state.origin in digest state flushing. |
| lib/http_aws_sigv4.c | Use data->state.origin->hostname for signing. |
| lib/ftp.c | Replace proxy-bit checks with Curl_conn_is_tunneling(). |
| lib/connect.c | Rework proxy filter setup using proxy peers + origin_is_proxy. |
| lib/cfilters.h | Declare new Curl_conn_is_tunneling(). |
| lib/cfilters.c | Implement Curl_conn_is_tunneling() by checking for CF_TYPE_PROXY filters. |
| lib/cf-socket.c | Remove unused data->info.conn_remote_port updates. |
| lib/cf-ip-happy.c | Update proxy-peer selection and peer equality checks. |
| docs/internals/PEERS.md | Document data->state.origin and forwarding vs tunneling proxy semantics. |
| docs/internals/CREDENTIALS.md | Update description to use data->state.origin rather than conn->origin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
transfer origin and proxy handling
Add
data->state.originas the origin the transfer is sending the current request to/gets the response from. Use it for request specific properties like authentication, hsts and cookie handling, etc.Unless talking to a forwarding HTTP proxy (e.g. not tunneling),
data->state.originandconn->originare the same. With a forwarding HTTP proxy in play,conn->originis set toconn->http_proxy.peerandconn->bits.origin_is_proxy(a new bit) is set.Remove the connection bits, now replaced with:
conn->bits.socksproxy->conn->socks_proy.peerconn->bits.httpproxy->conn->http_proy.peerconn->bits.proxy->(conn->socks_proy.peer || conn->http_proy.peer)conn->bits.tunnel_proxy-> (conn->http_proy.peer && !conn->bits.origin_is_proxy)(conn->bits.httpproxy && !conn->bits.tunnel_proxy)->conn->bits.origin_is_proxyRename
noproxy.[ch]toproxy.[ch]. Move the connection proxy setup code fromurl.ctoproxy.c.Remove
data->info.conn_remote_portas no one uses it.Add test_40_02b for a SOCKS connection to a forwarding HTTPS proxy.
Update internal documentation about peers and creds.