11package io .split .client ;
22
3+ import io .split .client .dtos .ProxyMTLSAuth ;
34import io .split .client .impressions .ImpressionListener ;
45import io .split .client .impressions .ImpressionsManager ;
56import io .split .client .utils .FileTypeEnum ;
@@ -34,6 +35,11 @@ public class SplitClientConfig {
3435 public static final String STREAMING_ENDPOINT = "https://streaming.split.io/sse" ;
3536 public static final String TELEMETRY_ENDPOINT = "https://telemetry.split.io/api/v1" ;
3637
38+ public static class HttpScheme {
39+ public static final String HTTP = "http" ;
40+ public static final String HTTPS = "https" ;
41+ }
42+
3743 private final String _endpoint ;
3844 private final String _eventsEndpoint ;
3945
@@ -85,6 +91,8 @@ public class SplitClientConfig {
8591 private final HttpHost _proxy ;
8692 private final String _proxyUsername ;
8793 private final String _proxyPassword ;
94+ private final String _proxyToken ;
95+ private final ProxyMTLSAuth _proxyMtlsAuth ;
8896
8997 // To be set during startup
9098 public static String splitSdkVersion ;
@@ -118,6 +126,8 @@ private SplitClientConfig(String endpoint,
118126 HttpHost proxy ,
119127 String proxyUsername ,
120128 String proxyPassword ,
129+ String proxyToken ,
130+ ProxyMTLSAuth proxyMtlsAuth ,
121131 int eventsQueueSize ,
122132 long eventSendIntervalInMillis ,
123133 int maxStringLength ,
@@ -171,6 +181,8 @@ private SplitClientConfig(String endpoint,
171181 _proxy = proxy ;
172182 _proxyUsername = proxyUsername ;
173183 _proxyPassword = proxyPassword ;
184+ _proxyToken = proxyToken ;
185+ _proxyMtlsAuth = proxyMtlsAuth ;
174186 _eventsQueueSize = eventsQueueSize ;
175187 _eventSendIntervalInMillis = eventSendIntervalInMillis ;
176188 _maxStringLength = maxStringLength ;
@@ -302,6 +314,14 @@ public String proxyPassword() {
302314 return _proxyPassword ;
303315 }
304316
317+ public String proxyToken () {
318+ return _proxyToken ;
319+ }
320+
321+ public ProxyMTLSAuth proxyMTLSAuth () {
322+ return _proxyMtlsAuth ;
323+ }
324+
305325 public long eventSendIntervalInMillis () {
306326 return _eventSendIntervalInMillis ;
307327 }
@@ -417,8 +437,8 @@ public boolean isSdkEndpointOverridden() {
417437 }
418438
419439 public CustomHttpModule alternativeHTTPModule () { return _alternativeHTTPModule ; }
420- public static final class Builder {
421440
441+ public static final class Builder {
422442 private String _endpoint = SDK_ENDPOINT ;
423443 private boolean _endpointSet = false ;
424444 private String _eventsEndpoint = EVENTS_ENDPOINT ;
@@ -440,8 +460,11 @@ public static final class Builder {
440460 private int _waitBeforeShutdown = 5000 ;
441461 private String _proxyHost = "localhost" ;
442462 private int _proxyPort = -1 ;
463+ private String _proxyScheme = HttpScheme .HTTP ;
443464 private String _proxyUsername ;
444465 private String _proxyPassword ;
466+ private String _proxyToken ;
467+ private ProxyMTLSAuth _proxyMtlsAuth ;
445468 private int _eventsQueueSize = 500 ;
446469 private long _eventSendIntervalInMillis = 30 * (long )1000 ;
447470 private int _maxStringLength = 250 ;
@@ -754,6 +777,17 @@ public Builder proxyPort(int proxyPort) {
754777 return this ;
755778 }
756779
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+
757791 /**
758792 * Set the username for authentication against the proxy (if proxy settings are enabled). (Optional).
759793 *
@@ -776,6 +810,28 @@ public Builder proxyPassword(String proxyPassword) {
776810 return this ;
777811 }
778812
813+ /**
814+ * Set the token for authentication against the proxy (if proxy settings are enabled). (Optional).
815+ *
816+ * @param proxyToken
817+ * @return this builder
818+ */
819+ public Builder proxyToken (String proxyToken ) {
820+ _proxyToken = proxyToken ;
821+ return this ;
822+ }
823+
824+ /**
825+ * Set the mtls authentication against the proxy (if proxy settings are enabled). (Optional).
826+ *
827+ * @param proxyMtlsAuth
828+ * @return this builder
829+ */
830+ public Builder proxyMtlsAuth (ProxyMTLSAuth proxyMtlsAuth ) {
831+ _proxyMtlsAuth = proxyMtlsAuth ;
832+ return this ;
833+ }
834+
779835 /**
780836 * Disables running destroy() on shutdown by default.
781837 *
@@ -788,7 +844,7 @@ public Builder disableDestroyOnShutDown() {
788844
789845 HttpHost proxy () {
790846 if (_proxyPort != -1 ) {
791- return new HttpHost (_proxyHost , _proxyPort );
847+ return new HttpHost (_proxyScheme , _proxyHost , _proxyPort );
792848 }
793849 // Default is no proxy.
794850 return null ;
@@ -1096,6 +1152,38 @@ private void verifyAlternativeClient() {
10961152 }
10971153 }
10981154
1155+ private void verifyProxy () {
1156+ if (_proxyPort == -1 ) {
1157+ return ;
1158+ }
1159+
1160+ if (!(_proxyScheme .equals (HttpScheme .HTTP ) || _proxyScheme .equals (HttpScheme .HTTPS ))) {
1161+ throw new IllegalArgumentException ("Proxy scheme must be either http or https." );
1162+ }
1163+
1164+ if (_proxyUsername == null && _proxyToken == null && _proxyMtlsAuth == null ) {
1165+ return ;
1166+ }
1167+
1168+ if (_proxyUsername != null && _proxyToken != null ) {
1169+ throw new IllegalArgumentException ("Proxy user and Proxy token params are updated, set only one param." );
1170+ }
1171+
1172+ if (_proxyUsername != null && _proxyMtlsAuth != null ) {
1173+ throw new IllegalArgumentException ("Proxy user and Proxy mTLS params are updated, set only one param." );
1174+ }
1175+
1176+ if (_proxyToken != null && _proxyMtlsAuth != null ) {
1177+ throw new IllegalArgumentException ("Proxy token and Proxy mTLS params are updated, set only one param." );
1178+ }
1179+
1180+ if (_proxyMtlsAuth != null ) {
1181+ if (_proxyMtlsAuth .getP12File () == null || _proxyMtlsAuth .getP12FilePassKey () == null ) {
1182+ throw new IllegalArgumentException ("Proxy mTLS must have p12 file path and name, and pass phrase." );
1183+ }
1184+ }
1185+ }
1186+
10991187 public SplitClientConfig build () {
11001188
11011189 verifyRates ();
@@ -1108,6 +1196,8 @@ public SplitClientConfig build() {
11081196
11091197 verifyAlternativeClient ();
11101198
1199+ verifyProxy ();
1200+
11111201 if (_numThreadsForSegmentFetch <= 0 ) {
11121202 throw new IllegalArgumentException ("Number of threads for fetching segments MUST be greater than zero" );
11131203 }
@@ -1133,6 +1223,8 @@ public SplitClientConfig build() {
11331223 proxy (),
11341224 _proxyUsername ,
11351225 _proxyPassword ,
1226+ _proxyToken ,
1227+ _proxyMtlsAuth ,
11361228 _eventsQueueSize ,
11371229 _eventSendIntervalInMillis ,
11381230 _maxStringLength ,
0 commit comments