Interface HttpClient.Builder
- Enclosing interface:
- HttpClient
-
Method Summary
Modifier and TypeMethodDescriptionaddCertificates(byte[] certificateBytes) Adds CA certificate bytes to the client's trust store.addCertificates(Path path) Adds a CA certificate file to the client's trust store.build()Creates a newHttpClientfrom the current state of this builder.Returns anHTTPClientwrapper that defers building the actual HTTP client until the wrapper'sHttpClient.send(java.net.http.HttpRequest, java.net.http.HttpResponse.BodyHandler<T>)method is called.setConnectTimeout(Duration timeout) Sets the timeout for connecting to a server.Configures HTTP connections to connect to the provided proxy address.setProxySelector(ProxySelector proxySelector) Sets the proxy selector to use when establishing connections.setRequestTimeout(Duration timeout) Sets the timeout for the interval between sending a request and receiving response headers.setTestPort(int port) Sets a test server's listening port.setUserAgent(String userAgent) Sets theUser-Agentheader.
-
Method Details
-
setUserAgent
Sets theUser-Agentheader.Defaults to
"Pkl/$version ($os; $flavor)". -
setConnectTimeout
Sets the timeout for connecting to a server.Defaults to 60 seconds.
-
setRequestTimeout
Sets the timeout for the interval between sending a request and receiving response headers.Defaults to 60 seconds. To set a timeout for a specific request, use
HttpRequest.Builder.timeout(java.time.Duration). -
addCertificates
Adds a CA certificate file to the client's trust store.The given file must contain X.509 certificates in PEM format.
If no CA certificates are added via this method nor
addCertificates(byte[]), the built-in CA certificates of the Pkl native executable or JVM are used. -
addCertificates
Adds CA certificate bytes to the client's trust store.The given cert must be an X.509 certificate in PEM format.
If no CA certificates are added via this method nor
addCertificates(Path), the built-in CA certificates of the Pkl native executable or JVM are used. -
setTestPort
Sets a test server's listening port.If set, requests that specify port 0 will be modified to use the given port. This is an internal test option.
-
setProxySelector
Sets the proxy selector to use when establishing connections.Defaults to:
ProxySelector.getDefault(). -
setProxy
Configures HTTP connections to connect to the provided proxy address.The provided
proxyAddressmust have scheme http, not contain userInfo, and not have a path segment.If
proxyAddressisnull, uses the proxy address provided byProxySelector.getDefault().NOTE: Due to a limitation in the JDK, this does not configure the proxy server used for certificate revocation checking. To configure the certificate revocation checker, the result of
ProxySelector.getDefault()needs to be changed either by setting system properties, or viaProxySelector.setDefault(java.net.ProxySelector).- Throws:
IllegalArgumentException- if `proxyAddress` is invalid.
-
build
HttpClient build()Creates a newHttpClientfrom the current state of this builder.- Throws:
HttpClientInitException- if an error occurs while initializing the client
-
buildLazily
HttpClient buildLazily()Returns anHTTPClientwrapper that defers building the actual HTTP client until the wrapper'sHttpClient.send(java.net.http.HttpRequest, java.net.http.HttpResponse.BodyHandler<T>)method is called.Note: When using this method, any exception thrown when building the actual HTTP client is equally deferred.
-