|
27 | 27 | import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder; |
28 | 28 | import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager; |
29 | 29 | import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder; |
| 30 | +import org.apache.hc.client5.http.routing.HttpRoutePlanner; |
30 | 31 | import org.apache.hc.core5.http.Header; |
| 32 | +import org.apache.hc.core5.http.HttpHost; |
31 | 33 | import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy; |
32 | 34 | import org.apache.hc.core5.util.Timeout; |
33 | 35 | import org.apache.hc.core5.util.VersionInfo; |
34 | 36 |
|
35 | 37 | import javax.net.ssl.SSLContext; |
36 | 38 | import java.io.IOException; |
37 | 39 | import java.io.InputStream; |
| 40 | +import java.net.ProxySelector; |
38 | 41 | import java.security.NoSuchAlgorithmException; |
39 | 42 | import java.util.List; |
40 | 43 | import java.util.Locale; |
@@ -75,6 +78,9 @@ public final class Rest5ClientBuilder { |
75 | 78 | private Header[] defaultHeaders = EMPTY_HEADERS; |
76 | 79 | private Rest5Client.FailureListener failureListener; |
77 | 80 | private SSLContext sslContext; |
| 81 | + private HttpHost proxy; |
| 82 | + private ProxySelector proxySelector; |
| 83 | + private HttpRoutePlanner routePlanner; |
78 | 84 | private String pathPrefix; |
79 | 85 | private NodeSelector nodeSelector = NodeSelector.ANY; |
80 | 86 | private boolean strictDeprecationMode = false; |
@@ -180,6 +186,24 @@ public Rest5ClientBuilder setSSLContext(SSLContext sslContext) { |
180 | 186 | return this; |
181 | 187 | } |
182 | 188 |
|
| 189 | + public Rest5ClientBuilder setProxy(HttpHost proxy) { |
| 190 | + Objects.requireNonNull(proxy, "proxy must not be null"); |
| 191 | + this.proxy = proxy; |
| 192 | + return this; |
| 193 | + } |
| 194 | + |
| 195 | + public Rest5ClientBuilder setProxySelector(ProxySelector proxySelector) { |
| 196 | + Objects.requireNonNull(proxySelector, "proxy selector must not be null"); |
| 197 | + this.proxySelector = proxySelector; |
| 198 | + return this; |
| 199 | + } |
| 200 | + |
| 201 | + public Rest5ClientBuilder setRoutePlanner(HttpRoutePlanner routePlanner) { |
| 202 | + Objects.requireNonNull(routePlanner, "route planner must not be null"); |
| 203 | + this.routePlanner = routePlanner; |
| 204 | + return this; |
| 205 | + } |
| 206 | + |
183 | 207 | /** |
184 | 208 | * Sets the default request headers, which will be sent along with each request. |
185 | 209 | * <p> |
@@ -374,6 +398,16 @@ private CloseableHttpAsyncClient createHttpClient() { |
374 | 398 | .setTargetAuthenticationStrategy(new DefaultAuthenticationStrategy()) |
375 | 399 | .setThreadFactory(new RestClientThreadFactory()); |
376 | 400 |
|
| 401 | + if (this.proxy != null) { |
| 402 | + httpClientBuilder.setProxy(this.proxy); |
| 403 | + } |
| 404 | + if (this.proxySelector != null) { |
| 405 | + httpClientBuilder.setProxySelector(this.proxySelector); |
| 406 | + } |
| 407 | + if (this.routePlanner != null) { |
| 408 | + httpClientBuilder.setRoutePlanner(this.routePlanner); |
| 409 | + } |
| 410 | + |
377 | 411 | return httpClientBuilder.build(); |
378 | 412 | } catch (NoSuchAlgorithmException e) { |
379 | 413 | throw new IllegalStateException("could not create the default ssl context", e); |
|
0 commit comments