2323import java .util .stream .Collectors ;
2424import org .apache .commons .io .IOUtils ;
2525import org .apache .http .*;
26+ import org .apache .http .client .HttpRequestRetryHandler ;
2627import org .apache .http .client .config .RequestConfig ;
2728import org .apache .http .client .methods .*;
2829import org .apache .http .conn .ssl .SSLConnectionSocketFactory ;
@@ -47,6 +48,7 @@ public static class Builder {
4748 private ProxyConfig proxyConfig ;
4849 private SSLConnectionSocketFactory sslSocketFactory ;
4950 private PoolingHttpClientConnectionManager connectionManager ;
51+ private HttpRequestRetryHandler requestRetryHandler ;
5052
5153 /**
5254 * @param databricksConfig The DatabricksConfig to use for the HttpClient. If the
@@ -96,6 +98,15 @@ public Builder withConnectionManager(PoolingHttpClientConnectionManager connecti
9698 return this ;
9799 }
98100
101+ /**
102+ * @param requestRetryHandler the HttpRequestRetryHandler to use for the HttpClient.
103+ * @return This builder.
104+ */
105+ public Builder withRequestRetryHandler (HttpRequestRetryHandler requestRetryHandler ) {
106+ this .requestRetryHandler = requestRetryHandler ;
107+ return this ;
108+ }
109+
99110 /** Builds a new instance of CommonsHttpClient with the configured parameters. */
100111 public CommonsHttpClient build () {
101112 return new CommonsHttpClient (this );
@@ -131,6 +142,9 @@ private CommonsHttpClient(Builder builder) {
131142 connectionManager .setMaxTotal (100 );
132143 httpClientBuilder .setConnectionManager (connectionManager );
133144 }
145+ if (builder .requestRetryHandler != null ) {
146+ httpClientBuilder .setRetryHandler (builder .requestRetryHandler );
147+ }
134148 hc = httpClientBuilder .build ();
135149 }
136150
0 commit comments