Skip to content

Added more setters in Rest5Builder #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager;
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
import org.apache.hc.client5.http.routing.HttpRoutePlanner;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy;
import org.apache.hc.core5.util.Timeout;
import org.apache.hc.core5.util.VersionInfo;

import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.io.InputStream;
import java.net.ProxySelector;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -75,6 +78,9 @@ public final class Rest5ClientBuilder {
private Header[] defaultHeaders = EMPTY_HEADERS;
private Rest5Client.FailureListener failureListener;
private SSLContext sslContext;
private HttpHost proxy;
private ProxySelector proxySelector;
private HttpRoutePlanner routePlanner;
private String pathPrefix;
private NodeSelector nodeSelector = NodeSelector.ANY;
private boolean strictDeprecationMode = false;
Expand Down Expand Up @@ -180,6 +186,24 @@ public Rest5ClientBuilder setSSLContext(SSLContext sslContext) {
return this;
}

public Rest5ClientBuilder setProxy(HttpHost proxy) {
Objects.requireNonNull(proxy, "proxy must not be null");
this.proxy = proxy;
return this;
}

public Rest5ClientBuilder setProxySelector(ProxySelector proxySelector) {
Objects.requireNonNull(proxySelector, "proxy selector must not be null");
this.proxySelector = proxySelector;
return this;
}

public Rest5ClientBuilder setRoutePlanner(HttpRoutePlanner routePlanner) {
Objects.requireNonNull(routePlanner, "route planner must not be null");
this.routePlanner = routePlanner;
return this;
}

/**
* Sets the default request headers, which will be sent along with each request.
* <p>
Expand Down Expand Up @@ -374,6 +398,16 @@ private CloseableHttpAsyncClient createHttpClient() {
.setTargetAuthenticationStrategy(new DefaultAuthenticationStrategy())
.setThreadFactory(new RestClientThreadFactory());

if (this.proxy != null) {
httpClientBuilder.setProxy(this.proxy);
}
if (this.proxySelector != null) {
httpClientBuilder.setProxySelector(this.proxySelector);
}
if (this.routePlanner != null) {
httpClientBuilder.setRoutePlanner(this.routePlanner);
}

return httpClientBuilder.build();
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException("could not create the default ssl context", e);
Expand Down
Loading