- java.lang.Object
-
- jdk.incubator.http.HttpClient.Builder
-
- Enclosing class:
- HttpClient
public abstract static class HttpClient.Builder extends Object
A builder of immutableHttpClients.
Incubating Feature. Will be removed in a future release.Builders are created by invoking newBuilder. Each of the setter methods modifies the state of the builder and returns the same instance. Builders are not thread-safe and should not be used concurrently from multiple threads without external synchronization.
- Since:
- 9
-
-
Field Summary
Fields Modifier and Type Field Description static ProxySelectorNO_PROXYA proxy selector that always returnProxy.NO_PROXYimplying a direct connection.
-
Constructor Summary
Constructors Modifier Constructor Description protectedBuilder()Creates a Builder.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract HttpClient.Builderauthenticator(Authenticator a)Sets an authenticator to use for HTTP authentication.abstract HttpClientbuild()Returns a newHttpClientbuilt from the current state of this builder.abstract HttpClient.BuildercookieHandler(CookieHandler cookieHandler)Sets a cookie handler.abstract HttpClient.Builderexecutor(Executor executor)Sets the executor to be used for asynchronous and dependent tasks.abstract HttpClient.BuilderfollowRedirects(HttpClient.Redirect policy)Specifies whether requests will automatically follow redirects issued by the server.abstract HttpClient.Builderpriority(int priority)Sets the default priority for any HTTP/2 requests sent from this client.abstract HttpClient.Builderproxy(ProxySelector selector)Sets aProxySelector.abstract HttpClient.BuildersslContext(SSLContext sslContext)Sets anSSLContext.abstract HttpClient.BuildersslParameters(SSLParameters sslParameters)Sets anSSLParameters.abstract HttpClient.Builderversion(HttpClient.Version version)Requests a specific HTTP protocol version where possible.
-
-
-
Field Detail
-
NO_PROXY
public static final ProxySelector NO_PROXY
A proxy selector that always returnProxy.NO_PROXYimplying a direct connection. This is a convenience object that can be passed toproxy(ProxySelector)in order to build an instance ofHttpClientthat uses no proxy.
-
-
Method Detail
-
cookieHandler
public abstract HttpClient.Builder cookieHandler(CookieHandler cookieHandler)
Sets a cookie handler.- Parameters:
cookieHandler- the cookie handler- Returns:
- this builder
-
sslContext
public abstract HttpClient.Builder sslContext(SSLContext sslContext)
Sets anSSLContext.If this method is not invoked prior to building, then newly built clients will use the default context, which is normally adequate for client applications that do not need to specify protocols, or require client authentication.
- Parameters:
sslContext- the SSLContext- Returns:
- this builder
-
sslParameters
public abstract HttpClient.Builder sslParameters(SSLParameters sslParameters)
Sets anSSLParameters.If this method is not invoked prior to building, then newly built clients will use a default, implementation specific, set of parameters.
Some parameters which are used internally by the HTTP Client implementation (such as the application protocol list) should not be set by callers, as they may be ignored. The contents of the given object are copied.
- Parameters:
sslParameters- the SSLParameters- Returns:
- this builder
-
executor
public abstract HttpClient.Builder executor(Executor executor)
Sets the executor to be used for asynchronous and dependent tasks.If this method is not invoked prior to building, a default executor is created for each newly built
HttpClient. The default executor uses a cached thread pool, with a custom thread factory.- Implementation Note:
- If a security manager has been installed, the thread factory creates threads that run with an access control context that has no permissions.
- Parameters:
executor- the Executor- Returns:
- this builder
-
followRedirects
public abstract HttpClient.Builder followRedirects(HttpClient.Redirect policy)
Specifies whether requests will automatically follow redirects issued by the server.If this method is not invoked prior to building, then newly built clients will use a default redirection policy of
NEVER.- Parameters:
policy- the redirection policy- Returns:
- this builder
-
version
public abstract HttpClient.Builder version(HttpClient.Version version)
Requests a specific HTTP protocol version where possible.If this method is not invoked prior to building, then newly built clients will prefer HTTP/2.
If set to HTTP/2, then each request will attempt to upgrade to HTTP/2. If the upgrade succeeds, then the response to this request will use HTTP/2 and all subsequent requests and responses to the same origin server will use HTTP/2. If the upgrade fails, then the response will be handled using HTTP/1.1
- Parameters:
version- the requested HTTP protocol version- Returns:
- this builder
-
priority
public abstract HttpClient.Builder priority(int priority)
Sets the default priority for any HTTP/2 requests sent from this client. The value provided must be between1and256(inclusive).- Parameters:
priority- the priority weighting- Returns:
- this builder
- Throws:
IllegalArgumentException- if the given priority is out of range
-
proxy
public abstract HttpClient.Builder proxy(ProxySelector selector)
Sets aProxySelector.- API Note:
ProxySelector.of(InetSocketAddress)provides aProxySelectorwhich uses a single proxy for all requests. The system-wide proxy selector can be retrieved byProxySelector.getDefault().- Implementation Note:
- If this method is not invoked prior to building, then newly built clients will use the default proxy selector, which
is normally adequate for client applications. This default
behavior can be turned off by supplying an explicit proxy
selector to this method, such as
NO_PROXYor one returned byProxySelector.of(InetSocketAddress), before callingbuild(). - Parameters:
selector- the ProxySelector- Returns:
- this builder
-
authenticator
public abstract HttpClient.Builder authenticator(Authenticator a)
Sets an authenticator to use for HTTP authentication.- Parameters:
a- the Authenticator- Returns:
- this builder
-
build
public abstract HttpClient build()
Returns a newHttpClientbuilt from the current state of this builder.- Returns:
- this builder
-
-