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 );
@@ -132,6 +143,9 @@ private CommonsHttpClient(Builder builder) {
132143 connectionManager .setMaxTotal (100 );
133144 httpClientBuilder .setConnectionManager (connectionManager );
134145 }
146+ if (builder .requestRetryHandler != null ) {
147+ httpClientBuilder .setRetryHandler (builder .requestRetryHandler );
148+ }
135149 hc = httpClientBuilder .build ();
136150 }
137151
0 commit comments