Repository navigation
Add an explicit proxy option to the sync and async clients - #157
Open
beniamin-levin wants to merge 1 commit into
Open
beniamin-levin wants to merge 1 commit into
beniamin-levin wants to merge 1 commit into
Conversation
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
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.
Why I built it
Both clients set
trust_env=Falseand bring their own transports, so the SDK ignoresHTTPS_PROXYand 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 withtransport-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
ProoflineClientandAsyncProoflineClienttake a keyword-onlyproxy: str | None = None. Environment variables are still never read; the README showsproxy=os.environ["HTTPS_PROXY"]for callers who want that.http://andhttps://proxy URLs with a host, optional port and optionaluser:passwordare accepted. TheValueErrornever repeats the value, because it can carry credentials. A proxy with a plain-HTTPbase_urlis refused, because the proxy would read the forwarded request and its token._sync_http.Transportbuildshttpcore2.HTTPProxyon the existing boundedNetworkBackend, 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 existingAsyncRetryTransportdeadline.httpcore2.ProxyError) was not mapped and surfaced asurn:proofline:sdk:invalid-response. It now maps tourn:proofline:sdk:transport-unavailable, anddetailnames only the proxy's status (407 needs credentials, 403 is the proxy's policy). It is not retried.Tests
tests/test_proxy.py, both clients: a real TLS origin (a throwaway certificate issued byopensslintmp_path) behind a loopback CONNECT proxy added totests/http_server.py. The tests check that the proxy seesCONNECT api.proofline.invalid:443with BasicProxy-Authorizationand never the bearer token, that the origin gets the token and its ownHost, 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 endswait_for_reviewat 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.pypass 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