Skip to content

fix(httpclient): honor system proxy settings in HttpClientFactoryImpl - #231

Open
pcbeingused333 wants to merge 1 commit into
Backblaze:masterfrom
pcbeingused333:fix/c2193-system-proxy
Open

pcbeingused333 wants to merge 1 commit into
Backblaze:masterfrom
pcbeingused333:fix/c2193-system-proxy

Conversation

@pcbeingused333

Copy link
Copy Markdown

Fixes #124

Cause. HttpClientFactoryImpl.create() builds the Apache client with HttpClients.custom() and never sets a route planner or useSystemProperties(), so https.proxyHost/https.proxyPort are ignored and every connection is direct. Simply enabling the system proxy is not enough: reaching a proxy needs a plain http connection to the proxy itself (before CONNECT to the https server), and the connection manager only registers http when setSupportInsecureHttp(true).

Fix. The factory now uses SystemDefaultRoutePlanner(ProxySelector.getDefault()), so the standard JVM properties (https.proxyHost, https.proxyPort, http.nonProxyHosts) apply; with no proxy configured, connections stay direct. The http scheme is registered so the proxy hop works, but a small route planner wrapper still rejects non-https destinations unless setSupportInsecureHttp(true) was used, so the "no accidental http" contract is unchanged. TLS context and hostname verification are untouched. Builder.setUseSystemProxy(false) opts out. CHANGELOG updated.

Test. HttpClientFactoryImplProxyTest runs a local fake proxy that answers 502 and checks that (1) an https request sends CONNECT b2.invalid:443 to it, (2) setUseSystemProxy(false) bypasses it, (3) http destinations are still rejected by default and (4) allowed when insecure http is enabled. Tests 1 and 4 fail on master and pass with the change; :b2-sdk-httpclient:test passes in full (Gradle 7.3, JDK 17).

Disclosure: this change was prepared with the help of an AI coding assistant (Claude) and submitted by a human contributor.

Fixes Backblaze#124. Use SystemDefaultRoutePlanner with the default ProxySelector so
https.proxyHost/https.proxyPort are respected. Reaching a proxy needs a plain
http connection to it, so the http scheme is registered, while a route planner
still rejects http destinations unless setSupportInsecureHttp(true).

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.

b2-sdk-httpclient ignoring proxy settings, could not access API

1 participant