@@ -129,11 +129,13 @@ public static Duration getSocketTimeout() {
129
129
@ SnowflakeJdbcInternalApi
130
130
public static void setConnectionTimeout (int timeout ) {
131
131
connectionTimeout = Duration .ofMillis (timeout );
132
+ initDefaultRequestConfig (connectionTimeout .toMillis (), getSocketTimeout ().toMillis ());
132
133
}
133
134
134
135
@ SnowflakeJdbcInternalApi
135
136
public static void setSocketTimeout (int timeout ) {
136
137
socketTimeout = Duration .ofMillis (timeout );
138
+ initDefaultRequestConfig (getConnectionTimeout ().toMillis (), socketTimeout .toMillis ());
137
139
}
138
140
139
141
public static long getDownloadedConditionTimeoutInSeconds () {
@@ -299,49 +301,11 @@ public static CloseableHttpClient buildHttpClient(
299
301
socketTimeout ,
300
302
timeToLive );
301
303
302
- // Set proxy settings for DefaultRequestConfig. If current proxy settings are the same as for
303
- // the last request, keep the current DefaultRequestConfig. If not, build a new
304
- // DefaultRequestConfig and set the new proxy settings for it
305
- HttpHost proxy =
306
- (key != null && key .usesProxy ())
307
- ? new HttpHost (
308
- key .getProxyHost (), key .getProxyPort (), key .getProxyHttpProtocol ().getScheme ())
309
- : null ;
310
- // If defaultrequestconfig is not initialized or its proxy settings do not match current proxy
311
- // settings, re-build it (current or old proxy settings could be null, so null check is
312
- // included)
313
- boolean noDefaultRequestConfig =
314
- DefaultRequestConfig == null || DefaultRequestConfig .getProxy () == null ;
315
- if (noDefaultRequestConfig || !DefaultRequestConfig .getProxy ().equals (proxy )) {
316
- RequestConfig .Builder builder =
317
- RequestConfig .custom ()
318
- .setConnectTimeout ((int ) connectTimeout )
319
- .setConnectionRequestTimeout ((int ) connectTimeout )
320
- .setSocketTimeout ((int ) socketTimeout );
321
- // only set the proxy settings if they are not null
322
- // but no value has been specified for nonProxyHosts
323
- // the route planner will determine whether to use a proxy based on nonProxyHosts value.
324
- String logMessage =
325
- "Rebuilding request config. Connect timeout: "
326
- + connectTimeout
327
- + " ms, connection request "
328
- + "timeout: "
329
- + connectTimeout
330
- + " ms, socket timeout: "
331
- + socketTimeout
332
- + " ms" ;
333
- if (proxy != null && Strings .isNullOrEmpty (key .getNonProxyHosts ())) {
334
- builder .setProxy (proxy );
335
- logMessage +=
336
- ", host: "
337
- + key .getProxyHost ()
338
- + ", port: "
339
- + key .getProxyPort ()
340
- + ", scheme: "
341
- + key .getProxyHttpProtocol ().getScheme ();
342
- }
343
- logger .debug (logMessage );
344
- DefaultRequestConfig = builder .build ();
304
+ // Create default request config without proxy since different connections could use different
305
+ // proxies in multi tenant environments
306
+ // Proxy is set later with route planner
307
+ if (DefaultRequestConfig == null ) {
308
+ initDefaultRequestConfig (connectTimeout , socketTimeout );
345
309
}
346
310
347
311
TrustManager [] trustManagers = null ;
@@ -411,11 +375,18 @@ public static CloseableHttpClient buildHttpClient(
411
375
.useSystemProperties ()
412
376
.setRedirectStrategy (new DefaultRedirectStrategy ())
413
377
.setUserAgent (buildUserAgent (userAgentSuffix )) // needed for Okta
414
- .disableCookieManagement (); // SNOW-39748
415
-
378
+ .disableCookieManagement () // SNOW-39748
379
+ . setDefaultRequestConfig ( DefaultRequestConfig );
416
380
if (key != null && key .usesProxy ()) {
381
+ HttpHost proxy =
382
+ new HttpHost (
383
+ key .getProxyHost (), key .getProxyPort (), key .getProxyHttpProtocol ().getScheme ());
417
384
logger .debug (
418
- "Instantiating proxy route planner with non-proxy hosts: {}" , key .getNonProxyHosts ());
385
+ "Configuring proxy and route planner - host: {}, port: {}, scheme: {}, nonProxyHosts: {}" ,
386
+ key .getProxyHost (),
387
+ key .getProxyPort (),
388
+ key .getProxyHttpProtocol ().getScheme (),
389
+ key .getNonProxyHosts ());
419
390
// use the custom proxy properties
420
391
SnowflakeMutableProxyRoutePlanner sdkProxyRoutePlanner =
421
392
httpClientRoutePlanner .computeIfAbsent (
@@ -426,7 +397,7 @@ public static CloseableHttpClient buildHttpClient(
426
397
key .getProxyPort (),
427
398
key .getProxyHttpProtocol (),
428
399
key .getNonProxyHosts ()));
429
- httpClientBuilder = httpClientBuilder .setProxy (proxy ).setRoutePlanner (sdkProxyRoutePlanner );
400
+ httpClientBuilder .setProxy (proxy ).setRoutePlanner (sdkProxyRoutePlanner );
430
401
if (!Strings .isNullOrEmpty (key .getProxyUser ())
431
402
&& !Strings .isNullOrEmpty (key .getProxyPassword ())) {
432
403
Credentials credentials =
@@ -440,20 +411,33 @@ public static CloseableHttpClient buildHttpClient(
440
411
key .getProxyHost (),
441
412
key .getProxyPort ());
442
413
credentialsProvider .setCredentials (authScope , credentials );
443
- httpClientBuilder = httpClientBuilder .setDefaultCredentialsProvider (credentialsProvider );
414
+ httpClientBuilder .setDefaultCredentialsProvider (credentialsProvider );
444
415
}
445
416
}
446
- httpClientBuilder .setDefaultRequestConfig (DefaultRequestConfig );
447
417
if (downloadUnCompressed ) {
448
418
logger .debug ("Disabling content compression for http client" );
449
- httpClientBuilder = httpClientBuilder .disableContentCompression ();
419
+ httpClientBuilder .disableContentCompression ();
450
420
}
451
421
return httpClientBuilder .build ();
452
422
} catch (NoSuchAlgorithmException | KeyManagementException ex ) {
453
423
throw new SSLInitializationException (ex .getMessage (), ex );
454
424
}
455
425
}
456
426
427
+ private static void initDefaultRequestConfig (long connectTimeout , long socketTimeout ) {
428
+ RequestConfig .Builder builder =
429
+ RequestConfig .custom ()
430
+ .setConnectTimeout ((int ) connectTimeout )
431
+ .setConnectionRequestTimeout ((int ) connectTimeout )
432
+ .setSocketTimeout ((int ) socketTimeout );
433
+ logger .debug (
434
+ "Rebuilding request config. Connect timeout: {} ms, connection request timeout: {} ms, socket timeout: {} ms" ,
435
+ connectTimeout ,
436
+ connectTimeout ,
437
+ socketTimeout );
438
+ DefaultRequestConfig = builder .build ();
439
+ }
440
+
457
441
public static void updateRoutePlanner (HttpClientSettingsKey key ) {
458
442
if (httpClientRoutePlanner .containsKey (key )
459
443
&& !httpClientRoutePlanner
0 commit comments