@@ -45,6 +45,7 @@ public class CommonsHttpClient implements HttpClient {
4545 public static class Builder {
4646 private DatabricksConfig databricksConfig ;
4747 private Integer timeoutSeconds ;
48+ private RequestConfig requestConfig ;
4849 private ProxyConfig proxyConfig ;
4950 private SSLConnectionSocketFactory sslSocketFactory ;
5051 private PoolingHttpClientConnectionManager connectionManager ;
@@ -63,14 +64,27 @@ public Builder withDatabricksConfig(DatabricksConfig databricksConfig) {
6364
6465 /**
6566 * @param timeoutSeconds The timeout in seconds to use for the HttpClient. This will override
66- * any timeout set in the DatabricksConfig.
67+ * any timeout set in the DatabricksConfig. Sets all three Apache HttpClient timeouts
68+ * (connect, socket, connection request) to the same value. For fine-grained control, use
69+ * {@link #withRequestConfig(RequestConfig)} instead.
6770 * @return This builder.
6871 */
6972 public Builder withTimeoutSeconds (int timeoutSeconds ) {
7073 this .timeoutSeconds = timeoutSeconds ;
7174 return this ;
7275 }
7376
77+ /**
78+ * @param requestConfig The Apache {@link RequestConfig} to use for the HttpClient. When set,
79+ * this takes precedence over {@link #withTimeoutSeconds(int)} and any timeout from {@link
80+ * DatabricksConfig}.
81+ * @return This builder.
82+ */
83+ public Builder withRequestConfig (RequestConfig requestConfig ) {
84+ this .requestConfig = requestConfig ;
85+ return this ;
86+ }
87+
7488 /**
7589 * @param proxyConfig the proxy configuration to use for the HttpClient.
7690 * @return This builder.
@@ -119,17 +133,12 @@ public CommonsHttpClient build() {
119133 private final CloseableHttpClient hc ;
120134
121135 private CommonsHttpClient (Builder builder ) {
122- int timeoutSeconds = 300 ;
123- if (builder .databricksConfig != null
124- && builder .databricksConfig .getHttpTimeoutSeconds () != null ) {
125- timeoutSeconds = builder .databricksConfig .getHttpTimeoutSeconds ();
126- }
127- if (builder .timeoutSeconds != null ) {
128- timeoutSeconds = builder .timeoutSeconds ;
129- }
130- int timeout = timeoutSeconds * 1000 ;
136+ RequestConfig requestConfig =
137+ builder .requestConfig != null
138+ ? builder .requestConfig
139+ : makeDefaultRequestConfig (builder .databricksConfig , builder .timeoutSeconds );
131140 HttpClientBuilder httpClientBuilder =
132- HttpClientBuilder .create ().setDefaultRequestConfig (makeRequestConfig ( timeout ) );
141+ HttpClientBuilder .create ().setDefaultRequestConfig (requestConfig );
133142 if (builder .proxyConfig != null ) {
134143 ProxyUtils .setupProxy (builder .proxyConfig , httpClientBuilder );
135144 }
@@ -150,7 +159,16 @@ private CommonsHttpClient(Builder builder) {
150159 hc = httpClientBuilder .build ();
151160 }
152161
153- private RequestConfig makeRequestConfig (int timeout ) {
162+ private static RequestConfig makeDefaultRequestConfig (
163+ DatabricksConfig databricksConfig , Integer timeoutSecondsOverride ) {
164+ int timeoutSeconds = 300 ;
165+ if (databricksConfig != null && databricksConfig .getHttpTimeoutSeconds () != null ) {
166+ timeoutSeconds = databricksConfig .getHttpTimeoutSeconds ();
167+ }
168+ if (timeoutSecondsOverride != null ) {
169+ timeoutSeconds = timeoutSecondsOverride ;
170+ }
171+ int timeout = timeoutSeconds * 1000 ;
154172 return RequestConfig .custom ()
155173 .setConnectionRequestTimeout (timeout )
156174 .setConnectTimeout (timeout )
0 commit comments