Skip to content

Commit 3cca5ea

Browse files
committed
Added proxy scheme
1 parent 2bc5767 commit 3cca5ea

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class SplitClientConfig {
3535
public static final String STREAMING_ENDPOINT = "https://streaming.split.io/sse";
3636
public static final String TELEMETRY_ENDPOINT = "https://telemetry.split.io/api/v1";
3737

38+
public static class HttpScheme {
39+
public static final String HTTP = "http";
40+
public static final String HTTPS = "https";
41+
}
42+
3843
private final String _endpoint;
3944
private final String _eventsEndpoint;
4045

@@ -455,6 +460,7 @@ public static final class Builder {
455460
private int _waitBeforeShutdown = 5000;
456461
private String _proxyHost = "localhost";
457462
private int _proxyPort = -1;
463+
private String _proxyScheme = HttpScheme.HTTP;
458464
private String _proxyUsername;
459465
private String _proxyPassword;
460466
private String _proxyToken;
@@ -771,6 +777,17 @@ public Builder proxyPort(int proxyPort) {
771777
return this;
772778
}
773779

780+
/**
781+
* The http scheme of the proxy. Default is http.
782+
*
783+
* @param proxyScheme protocol for the proxy
784+
* @return this builder
785+
*/
786+
public Builder proxyScheme(String proxyScheme) {
787+
_proxyScheme = proxyScheme;
788+
return this;
789+
}
790+
774791
/**
775792
* Set the username for authentication against the proxy (if proxy settings are enabled). (Optional).
776793
*
@@ -827,7 +844,7 @@ public Builder disableDestroyOnShutDown() {
827844

828845
HttpHost proxy() {
829846
if (_proxyPort != -1) {
830-
return new HttpHost(_proxyHost, _proxyPort);
847+
return new HttpHost(_proxyScheme, _proxyHost, _proxyPort);
831848
}
832849
// Default is no proxy.
833850
return null;
@@ -1140,6 +1157,10 @@ private void verifyProxy() {
11401157
return;
11411158
}
11421159

1160+
if (!(_proxyScheme.equals(HttpScheme.HTTP) || _proxyScheme.equals(HttpScheme.HTTPS))) {
1161+
throw new IllegalArgumentException("Proxy scheme must be either http or https.");
1162+
}
1163+
11431164
if (_proxyUsername == null && _proxyToken == null && _proxyMtlsAuth == null) {
11441165
return;
11451166
}

client/src/test/java/io/split/client/SplitClientConfigTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ public void checkProxyParams() {
266266
config = SplitClientConfig.builder()
267267
.proxyHost("proxy-host")
268268
.proxyPort(8888)
269+
.proxyScheme(SplitClientConfig.HttpScheme.HTTPS)
269270
.proxyUsername("user")
270271
.proxyPassword("pass")
271272
.build();
@@ -288,6 +289,15 @@ public void checkProxyParams() {
288289
Assert.assertEquals("pass-key", config.proxyMTLSAuth().getP12FilePassKey());
289290
}
290291

292+
@Test(expected = IllegalArgumentException.class)
293+
public void cannotUseInvalidHttpScheme() {
294+
SplitClientConfig.builder()
295+
.proxyHost("proxy-host")
296+
.proxyPort(8888)
297+
.proxyScheme("ftp")
298+
.build();
299+
}
300+
291301
@Test(expected = IllegalArgumentException.class)
292302
public void cannotUseProxyTokenAndProxyUsername() {
293303
SplitClientConfig.builder()

0 commit comments

Comments
 (0)