- java.lang.Object
-
- jdk.incubator.http.HttpClient.Builder
-
- Enclosing class:
- HttpClient
public abstract static class HttpClient.Builder extends Object
A builder of immutableHttpClient
s.HttpClient.Builder
s are created by callingHttpClient.newBuilder()
.
Incubating Feature. Will be removed in a future release.Each of the setter methods in this class modifies the state of the builder and returns this (ie. the same instance). The methods are not synchronized and should not be called from multiple threads without external synchronization.
build()
returns a newHttpClient
each time it is called.- Since:
- 9
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Builder()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract HttpClient.Builder
authenticator(Authenticator a)
Sets an authenticator to use for HTTP authentication.abstract HttpClient
build()
Returns aHttpClient
built from the current state of this builder.abstract HttpClient.Builder
cookieManager(CookieManager cookieManager)
Sets a cookie manager.abstract HttpClient.Builder
executor(Executor executor)
Sets the executor to be used for asynchronous tasks.abstract HttpClient.Builder
followRedirects(HttpClient.Redirect policy)
Specifies whether requests will automatically follow redirects issued by the server.abstract HttpClient.Builder
priority(int priority)
Sets the default priority for any HTTP/2 requests sent from this client.abstract HttpClient.Builder
proxy(ProxySelector selector)
Sets aProxySelector
for this client.abstract HttpClient.Builder
sslContext(SSLContext sslContext)
Sets anSSLContext
.abstract HttpClient.Builder
sslParameters(SSLParameters sslParameters)
Sets anSSLParameters
.abstract HttpClient.Builder
version(HttpClient.Version version)
Requests a specific HTTP protocol version where possible.
-
-
-
Method Detail
-
cookieManager
public abstract HttpClient.Builder cookieManager(CookieManager cookieManager)
Sets a cookie manager.- Parameters:
cookieManager
- the cookie manager- Returns:
- this builder
-
sslContext
public abstract HttpClient.Builder sslContext(SSLContext sslContext)
Sets anSSLContext
. If a security manager is set, then the caller must have theNetPermission
("setSSLContext"
)The effect of not calling this method, is that a default
SSLContext
is used, 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
- Throws:
SecurityException
- if a security manager is set and the caller does not have any required permission
-
sslParameters
public abstract HttpClient.Builder sslParameters(SSLParameters sslParameters)
Sets anSSLParameters
. If this method is not called, then a default set of parameters are used. The contents of the given object are copied. Some parameters which are used internally by the HTTP protocol implementation (such as application protocol list) should not be set by callers, as they are ignored.- Parameters:
sslParameters
- the SSLParameters- Returns:
- this builder
-
executor
public abstract HttpClient.Builder executor(Executor executor)
Sets the executor to be used for asynchronous tasks. If this method is not called, a default executor is set, which is the one returned fromExecutors.newCachedThreadPool
.- 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. This setting can be overridden on each request. The default value for this setting isNEVER
- 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 not set, the version defaults toHttpClient.Version.HTTP_2
. IfHttpClient.Version.HTTP_2
is set, 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 between1
and256
(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
for this client. If no selector is set, then no proxies are used. If anull
parameter is given then the system wide default proxy selector is used.- Implementation Note:
ProxySelector.of(InetSocketAddress)
provides aProxySelector
which uses one proxy for all requests.- 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 aHttpClient
built from the current state of this builder.- Returns:
- this builder
-
-