Skip to content

transfer origin and proxy handling#21967

Closed
icing wants to merge 1 commit into
curl:masterfrom
icing:data-origin
Closed

transfer origin and proxy handling#21967
icing wants to merge 1 commit into
curl:masterfrom
icing:data-origin

Conversation

@icing

@icing icing commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

transfer origin and proxy handling

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.

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.
@icing icing changed the title Data origin transfer origin and proxy handling Jun 12, 2026
@icing icing marked this pull request as ready for review June 12, 2026 10:23
@icing icing requested a review from bagder June 12, 2026 10:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.origin and update request-scoped features (auth/SPN, HSTS upgrades, cookies, alt-svc, AWS SigV4, etc.) to use it instead of conn->origin.
  • Consolidate proxy configuration/NO_PROXY parsing into new lib/proxy.[ch], replacing several conn->bits.*proxy* flags with conn->(socks|http)_proxy.peer and conn->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.

Comment thread tests/http/test_40_socks.py
@bagder bagder closed this in 73daec6 Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants