Skip to content

Commit 2814b86

Browse files
committed
External timeout
1 parent 79317ce commit 2814b86

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/main/java/io/split/android/client/network/SslProxyTunnelEstablisher.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,24 @@ class SslProxyTunnelEstablisher {
2525

2626
private static final String CRLF = "\r\n";
2727
private static final String PROXY_AUTHORIZATION_HEADER = "Proxy-Authorization";
28+
29+
// Default timeout for regular connections (10 seconds)
30+
private static final int DEFAULT_SOCKET_TIMEOUT = 10000;
2831

32+
/**
33+
* Establishes an SSL tunnel through the proxy using the CONNECT method.
34+
* After successful tunnel establishment, extracts the underlying socket
35+
* for use with origin server SSL connections.
36+
*
37+
* @param proxyHost The proxy server hostname
38+
* @param proxyPort The proxy server port
39+
* @param targetHost The target server hostname
40+
* @param targetPort The target server port
41+
* @param sslSocketFactory SSL socket factory for proxy authentication
42+
* @param proxyCredentialsProvider Credentials provider for proxy authentication
43+
* @return Raw socket with tunnel established (connection maintained)
44+
* @throws IOException if tunnel establishment fails
45+
*/
2946
/**
3047
* Establishes an SSL tunnel through the proxy using the CONNECT method.
3148
* After successful tunnel establishment, extracts the underlying socket
@@ -52,14 +69,17 @@ public Socket establishTunnel(@NonNull String proxyHost,
5269
SSLSocket sslSocket = null;
5370

5471
try {
72+
// Determine which timeout to use based on connection type
73+
int timeout = DEFAULT_SOCKET_TIMEOUT;
74+
5575
// Step 1: Create raw TCP connection to proxy
5676
rawSocket = new Socket(proxyHost, proxyPort);
57-
rawSocket.setSoTimeout(10000); // 10 second timeout
77+
rawSocket.setSoTimeout(timeout);
5878

5979
// Create a temporary SSL socket to establish the SSL session with proper trust validation
6080
sslSocket = (SSLSocket) sslSocketFactory.createSocket(rawSocket, proxyHost, proxyPort, false);
6181
sslSocket.setUseClientMode(true);
62-
sslSocket.setSoTimeout(10000); // 10 second timeout
82+
sslSocket.setSoTimeout(timeout);
6383

6484
// Perform SSL handshake using the SSL socket with custom CA certificates
6585
sslSocket.startHandshake();
@@ -108,7 +128,7 @@ public Socket establishTunnel(@NonNull String proxyHost,
108128
private void sendConnectRequest(@NonNull SSLSocket sslSocket,
109129
@NonNull String targetHost,
110130
int targetPort,
111-
@Nullable ProxyCredentialsProvider proxyCredentialsProvider) throws IOException {
131+
@Nullable BearerCredentialsProvider proxyCredentialsProvider) throws IOException {
112132

113133
Logger.v("Sending CONNECT request through SSL: CONNECT " + targetHost + ":" + targetPort + " HTTP/1.1");
114134

@@ -118,7 +138,7 @@ private void sendConnectRequest(@NonNull SSLSocket sslSocket,
118138

119139
if (proxyCredentialsProvider != null) {
120140
// Send Proxy-Authorization header if credentials are set
121-
String bearerToken = proxyCredentialsProvider.getBearerToken();
141+
String bearerToken = proxyCredentialsProvider.getToken();
122142
if (bearerToken != null && !bearerToken.trim().isEmpty()) {
123143
writer.write(PROXY_AUTHORIZATION_HEADER + ": Bearer " + bearerToken + CRLF);
124144
}

src/test/java/io/split/android/client/SplitFactoryHelperTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class SplitFactoryHelperTest {
195195
SplitFactoryBuilder.build("sdk_key", Key("user"), SplitClientConfig.builder().proxyConfiguration(
196196
ProxyConfiguration.builder().build()).build(), context)
197197
} catch (splitInstantiationException: SplitInstantiationException) {
198-
exceptionThrown = splitInstantiationException.cause!!.message!!.contains("When configured, proxy host cannot be null")
198+
exceptionThrown = (splitInstantiationException.message ?: "").contains("When configured, proxy host cannot be null")
199199
}
200200

201201
assertTrue(exceptionThrown)
@@ -208,7 +208,7 @@ class SplitFactoryHelperTest {
208208
SplitFactoryBuilder.build("sdk_key", Key("user"), SplitClientConfig.builder().proxyConfiguration(
209209
ProxyConfiguration.builder().url("http://localhost:8080").build()).build(), context)
210210
} catch (splitInstantiationException: SplitInstantiationException) {
211-
exceptionThrown = splitInstantiationException.message!!.contains("When configured, proxy host cannot be null")
211+
exceptionThrown = (splitInstantiationException.message ?: "").contains("When configured, proxy host cannot be null")
212212
}
213213

214214
assertFalse(exceptionThrown)

0 commit comments

Comments
 (0)