Skip to content

Commit 77c681a

Browse files
committed
polishing
1 parent e228e1d commit 77c681a

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

client/src/main/java/io/split/client/SplitClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ private void verifyProxy() {
11421142
if (_proxyConfiguration == null)
11431143
return;
11441144

1145-
if (!_proxyHost.equals("localhost")) {
1145+
if (_proxyPort != -1) {
11461146
_log.warn("Both the deprecated proxy configuration methods (`proxyHost`, `proxyPort`, `proxyUsername`, or `proxyPassword`) " +
11471147
"and the new `ProxyConfiguration` builder are being used. `ProxyConfiguration` will take precedence.");
11481148
}

client/src/main/java/io/split/client/SplitFactoryImpl.java

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -636,49 +636,48 @@ private static HttpClientBuilder setupProxy(HttpClientBuilder httpClientbuilder,
636636
}
637637

638638
private static HttpClientBuilder useLegacyProxyConfiguration(HttpClientBuilder httpClientbuilder, SplitClientConfig config) {
639-
HttpHost proxyHost;
640-
String userName = null;
641-
String password = null;
642-
proxyHost = config.proxy();
639+
HttpHost proxyHost = config.proxy();
640+
httpClientbuilder = addProxyHost(httpClientbuilder, proxyHost);
643641
if (config.proxyUsername() != null && config.proxyPassword() != null) {
644-
userName = config.proxyUsername();
645-
password = config.proxyPassword();
642+
return addProxyBasicAuth(httpClientbuilder, proxyHost, config.proxyUsername(), config.proxyPassword());
646643
}
647-
return addProxyParams(httpClientbuilder, proxyHost, userName, password);
644+
645+
return httpClientbuilder;
648646
}
649647

650648
private static HttpClientBuilder useProxyConfiguration(HttpClientBuilder httpClientbuilder, SplitClientConfig config) {
651-
HttpHost proxyHost;
652-
String userName = null;
653-
String password = null;
654-
proxyHost = config.proxyConfiguration().getHost();
655-
if (config.proxyConfiguration().getProxyCredentialsProvider() != null) {
656-
if (config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BasicCredentialsProvider) {
657-
io.split.client.dtos.BasicCredentialsProvider basicAuth =
658-
(io.split.client.dtos.BasicCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider();
659-
userName = basicAuth.getUsername();
660-
password = basicAuth.getPassword();
661-
} else if (config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BearerCredentialsProvider) {
662-
_log.debug("Proxy setup using Bearer token");
663-
httpClientbuilder.setDefaultCredentialsProvider(new HttpClientDynamicCredentials(
664-
(BearerCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider()));
665-
}
649+
HttpHost proxyHost = config.proxyConfiguration().getHost();
650+
httpClientbuilder = addProxyHost(httpClientbuilder, proxyHost);
651+
if (config.proxyConfiguration().getProxyCredentialsProvider() == null) {
652+
return httpClientbuilder;
666653
}
667-
return addProxyParams(httpClientbuilder, proxyHost, userName, password);
654+
655+
if (config.proxyConfiguration().getProxyCredentialsProvider() instanceof io.split.client.dtos.BasicCredentialsProvider) {
656+
io.split.client.dtos.BasicCredentialsProvider basicAuth =
657+
(io.split.client.dtos.BasicCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider();
658+
return addProxyBasicAuth(httpClientbuilder, proxyHost, basicAuth.getUsername(), basicAuth.getPassword());
659+
}
660+
661+
_log.debug("Proxy setup using Bearer token");
662+
httpClientbuilder.setDefaultCredentialsProvider(new HttpClientDynamicCredentials(
663+
(BearerCredentialsProvider) config.proxyConfiguration().getProxyCredentialsProvider()));
664+
return httpClientbuilder;
668665
}
669666

670-
private static HttpClientBuilder addProxyParams(HttpClientBuilder httpClientbuilder, HttpHost proxyHost, String userName, String password) {
667+
private static HttpClientBuilder addProxyHost(HttpClientBuilder httpClientbuilder, HttpHost proxyHost) {
671668
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxyHost);
672669
httpClientbuilder.setRoutePlanner(routePlanner);
673-
if (userName != null && password != null) {
674-
_log.debug("Proxy setup using Basic authentication");
675-
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
676-
AuthScope siteScope = new AuthScope(proxyHost.getHostName(), proxyHost.getPort());
677-
Credentials siteCreds = new UsernamePasswordCredentials(userName,
678-
password.toCharArray());
679-
credsProvider.setCredentials(siteScope, siteCreds);
680-
httpClientbuilder.setDefaultCredentialsProvider(credsProvider);
681-
}
670+
return httpClientbuilder;
671+
}
672+
673+
private static HttpClientBuilder addProxyBasicAuth(HttpClientBuilder httpClientbuilder, HttpHost proxyHost, String userName, String password) {
674+
_log.debug("Proxy setup using Basic authentication");
675+
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
676+
AuthScope siteScope = new AuthScope(proxyHost.getHostName(), proxyHost.getPort());
677+
Credentials siteCreds = new UsernamePasswordCredentials(userName,
678+
password.toCharArray());
679+
credsProvider.setCredentials(siteScope, siteCreds);
680+
httpClientbuilder.setDefaultCredentialsProvider(credsProvider);
682681
return httpClientbuilder;
683682
}
684683

0 commit comments

Comments
 (0)