Skip to content

Add an explicit proxy option to the sync and async clients - #157

Open
beniamin-levin wants to merge 1 commit into
prooflinedev:mainfrom
beniamin-levin:feat/explicit-proxy
Open

beniamin-levin wants to merge 1 commit into
prooflinedev:mainfrom
beniamin-levin:feat/explicit-proxy

Conversation

@beniamin-levin

Copy link
Copy Markdown

Why I built it

Both clients set trust_env=False and bring their own transports, so the SDK ignores HTTPS_PROXY and has no other way to reach the API through a forward proxy. On a network whose only route out is a proxy, which describes a lot of self-hosted CI runners and corporate networks, every SDK call fails with transport-unavailable. The Proofline CLI works on the same machine because it builds its reqwest client with the default proxy handling. I wanted the SDK to work there too, without dropping the choice not to read the environment.

Who it helps

Teams that call the SDK from CI runners or services behind an egress proxy: waiting for a review in a pipeline, uploading coverage, or reading exports from a job inside a corporate network. Today they have no supported option. This PR complements #77 (extra CA roots for TLS-inspecting proxies): this one covers plain CONNECT proxies, and the two work together for inspecting ones.

How I built it

  • ProoflineClient and AsyncProoflineClient take a keyword-only proxy: str | None = None. Environment variables are still never read; the README shows proxy=os.environ["HTTPS_PROXY"] for callers who want that.
  • Only http:// and https:// proxy URLs with a host, optional port and optional user:password are accepted. The ValueError never repeats the value, because it can carry credentials. A proxy with a plain-HTTP base_url is refused, because the proxy would read the forwarded request and its token.
  • Every request goes through a CONNECT tunnel to the HTTPS origin. The proxy sees the host, port and its own Basic credentials; the bearer token stays inside the TLS session with Proofline, and the proxy resolves the origin's name.
  • Sync: _sync_http.Transport builds httpcore2.HTTPProxy on the existing bounded NetworkBackend, so the HTTP timeout and a wait's deadline still bound the proxy connection, the CONNECT exchange and the TLS handshake inside the tunnel. Async: httpx2.AsyncHTTPTransport(proxy=...) inside the existing AsyncRetryTransport deadline.
  • In the sync transport a refused tunnel (httpcore2.ProxyError) was not mapped and surfaced as urn:proofline:sdk:invalid-response. It now maps to urn:proofline:sdk:transport-unavailable, and detail names only the proxy's status (407 needs credentials, 403 is the proxy's policy). It is not retried.
  • No change to the OpenAPI contract, generated code or workflows.

Tests

tests/test_proxy.py, both clients: a real TLS origin (a throwaway certificate issued by openssl in tmp_path) behind a loopback CONNECT proxy added to tests/http_server.py. The tests check that the proxy sees CONNECT api.proofline.invalid:443 with Basic Proxy-Authorization and never the bearer token, that the origin gets the token and its own Host, that two calls share one tunnel, and that the origin's name is never resolved locally. They also cover 407 and 403 refusals (no token, password or user name in the error), a silent proxy that still ends wait_for_review at its deadline, rejected URL shapes, and the plain-HTTP refusal. Removing the proxy wiring fails 8 of them, and removing the sync error mapping fails the 2 sync refusal tests.

The steps of scripts/check.py pass locally: generation check, contracts, ruff, ruff format, mypy, 264 tests, wheel and sdist builds, and the install smoke test for both artifacts.

🤖 Generated with Claude Code

Both clients set trust_env=False and use their own transports, so they
ignore HTTPS_PROXY and offer no other way to reach the API through a
forward proxy. On a network whose only route out is a proxy, such as many
self-hosted CI runners, every call fails with transport-unavailable, while
the Proofline CLI builds its reqwest client with the default proxy
handling, which reads HTTPS_PROXY.

ProoflineClient and AsyncProoflineClient now take proxy="http(s)://...".
Requests go through a CONNECT tunnel to the HTTPS origin, so the bearer
token stays inside the TLS session and the proxy resolves the origin's
name. The sync tunnel uses the existing bounded network backend, so the
HTTP timeout and a wait's deadline still bound the proxy connection and the
CONNECT exchange. A plain HTTP base_url with a proxy is refused, proxy URLs
are validated without echoing them, and a refused tunnel (407, 403) maps to
transport-unavailable naming only the proxy's status instead of surfacing
from the sync transport as an invalid API response.

This branch has not been deployed

No deployments
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