Repository navigation
fix(httpclient): honor system proxy settings in HttpClientFactoryImpl - #231
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
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
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.
Fixes #124
Cause.
HttpClientFactoryImpl.create()builds the Apache client withHttpClients.custom()and never sets a route planner oruseSystemProperties(), sohttps.proxyHost/https.proxyPortare ignored and every connection is direct. Simply enabling the system proxy is not enough: reaching a proxy needs a plainhttpconnection to the proxy itself (beforeCONNECTto the https server), and the connection manager only registershttpwhensetSupportInsecureHttp(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. Thehttpscheme is registered so the proxy hop works, but a small route planner wrapper still rejects non-https destinations unlesssetSupportInsecureHttp(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.
HttpClientFactoryImplProxyTestruns a local fake proxy that answers 502 and checks that (1) an https request sendsCONNECT b2.invalid:443to 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:testpasses 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.