@@ -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 }
0 commit comments