java.lang.Object
org.miaixz.bus.http.plugin.httpz.HttpBuilder
A fluent builder for configuring and creating an
Httpz.Client instance. This class wraps an
Httpd.Builder to provide a simplified, chainable interface for setting up the underlying HTTP client.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new builder with a default client configuration.HttpBuilder(Httpd httpd) Creates a new builder based on the configuration of an existingHttpdclient. -
Method Summary
Modifier and TypeMethodDescriptionaddInterceptor(Interceptor interceptor) Adds an application interceptor to this client.addNetworkInterceptor(Interceptor interceptor) Adds a network interceptor to this client.authenticator(Authenticator authenticator) Sets the authenticator used to respond to challenges from origin servers.build()Creates anHttpz.Clientwith the configured settings.Sets the response cache to be used by this client.certificatePinner(CertificatePinner certificatePinner) Sets the certificate pinner used to constrain which certificates are trusted.connectionPool(ConnectionPool connectPool) Sets the connection pool used to recycle HTTP and HTTPS connections.connectionSpecs(List<ConnectionSuite> connectSuites) Configures the connection specs used by this client.connectTimeout(long timeout, TimeUnit unit) Sets the default connect timeout for new connections.Sets the cookie handler for this client.dispatcher(Dispatcher dispatcher) Sets the dispatcher used to execute asynchronous requests.Sets the DNS service used to lookup IP addresses for hostnames.followRedirects(boolean followRedirects) Configures this client to follow redirects.followSslRedirects(boolean followProtocolRedirects) Configures this client to follow redirects from HTTPS to HTTP and from HTTP to HTTPS.Returns the underlyingHttpd.Builderfor advanced configuration.hostnameVerifier(HostnameVerifier hostnameVerifier) Sets the verifier used to confirm that response certificates apply to the requested hostnames.pingInterval(long interval, TimeUnit unit) Sets the ping interval for web socket connections.Configures the protocols used by this client.Sets the HTTP proxy that will be used by connections created by this client.proxyAuthenticator(Authenticator proxyAuthenticator) Sets the authenticator used to respond to challenges from proxy servers.proxySelector(ProxySelector proxySelector) Sets the proxy selection policy for this client.readTimeout(long timeout, TimeUnit unit) Sets the default read timeout for new connections.retryOnConnectionFailure(boolean retryOnConnectionFailure) Configures this client to retry or not retry IO failures.socketFactory(SocketFactory socketFactory) Sets the socket factory used to create connections.sslContext(SSLContext sslContext) A convenience method to configure a customSSLContext.sslSocketFactory(SSLSocketFactory sslSocketFactory) Deprecated.sslSocketFactory(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager) Sets the SSL socket factory and trust manager used to secure HTTPS connections.writeTimeout(long timeout, TimeUnit unit) Sets the default write timeout for new connections.
-
Constructor Details
-
HttpBuilder
public HttpBuilder()Creates a new builder with a default client configuration. -
HttpBuilder
Creates a new builder based on the configuration of an existingHttpdclient.- Parameters:
httpd- The client whose configuration will be copied.
-
-
Method Details
-
connectTimeout
Sets the default connect timeout for new connections.- Parameters:
timeout- The timeout value.unit- The time unit for the timeout.- Returns:
- This builder instance for chaining.
-
readTimeout
Sets the default read timeout for new connections.- Parameters:
timeout- The timeout value.unit- The time unit for the timeout.- Returns:
- This builder instance for chaining.
-
writeTimeout
Sets the default write timeout for new connections.- Parameters:
timeout- The timeout value.unit- The time unit for the timeout.- Returns:
- This builder instance for chaining.
-
pingInterval
Sets the ping interval for web socket connections.- Parameters:
interval- The interval value.unit- The time unit for the interval.- Returns:
- This builder instance for chaining.
-
proxy
Sets the HTTP proxy that will be used by connections created by this client.- Parameters:
proxy- The proxy to use.- Returns:
- This builder instance for chaining.
-
proxySelector
Sets the proxy selection policy for this client.- Parameters:
proxySelector- The proxy selector.- Returns:
- This builder instance for chaining.
-
cookieJar
Sets the cookie handler for this client.- Parameters:
cookieJar- The cookie jar.- Returns:
- This builder instance for chaining.
-
cache
Sets the response cache to be used by this client.- Parameters:
cache- The cache.- Returns:
- This builder instance for chaining.
-
dns
Sets the DNS service used to lookup IP addresses for hostnames.- Parameters:
dnsX- The custom DNS service.- Returns:
- This builder instance for chaining.
-
socketFactory
Sets the socket factory used to create connections.- Parameters:
socketFactory- The socket factory.- Returns:
- This builder instance for chaining.
-
sslSocketFactory
Deprecated.UsesslSocketFactory(SSLSocketFactory, X509TrustManager)instead.Sets the SSL socket factory used to secure HTTPS connections.- Parameters:
sslSocketFactory- The SSL socket factory.- Returns:
- This builder instance for chaining.
-
sslSocketFactory
public HttpBuilder sslSocketFactory(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager) Sets the SSL socket factory and trust manager used to secure HTTPS connections.- Parameters:
sslSocketFactory- The SSL socket factory.trustManager- The trust manager.- Returns:
- This builder instance for chaining.
-
hostnameVerifier
Sets the verifier used to confirm that response certificates apply to the requested hostnames.- Parameters:
hostnameVerifier- The hostname verifier.- Returns:
- This builder instance for chaining.
-
certificatePinner
Sets the certificate pinner used to constrain which certificates are trusted.- Parameters:
certificatePinner- The certificate pinner.- Returns:
- This builder instance for chaining.
-
authenticator
Sets the authenticator used to respond to challenges from origin servers.- Parameters:
authenticator- The authenticator.- Returns:
- This builder instance for chaining.
-
proxyAuthenticator
Sets the authenticator used to respond to challenges from proxy servers.- Parameters:
proxyAuthenticator- The proxy authenticator.- Returns:
- This builder instance for chaining.
-
connectionPool
Sets the connection pool used to recycle HTTP and HTTPS connections.- Parameters:
connectPool- The connection pool.- Returns:
- This builder instance for chaining.
-
followSslRedirects
Configures this client to follow redirects from HTTPS to HTTP and from HTTP to HTTPS.- Parameters:
followProtocolRedirects-trueto follow redirects across protocols.- Returns:
- This builder instance for chaining.
-
followRedirects
Configures this client to follow redirects.- Parameters:
followRedirects-trueto follow redirects.- Returns:
- This builder instance for chaining.
-
retryOnConnectionFailure
Configures this client to retry or not retry IO failures.- Parameters:
retryOnConnectionFailure-trueto retry on connection failures.- Returns:
- This builder instance for chaining.
-
dispatcher
Sets the dispatcher used to execute asynchronous requests.- Parameters:
dispatcher- The dispatcher.- Returns:
- This builder instance for chaining.
-
protocols
Configures the protocols used by this client.- Parameters:
protocols- The list of protocols.- Returns:
- This builder instance for chaining.
-
connectionSpecs
Configures the connection specs used by this client.- Parameters:
connectSuites- The list of connection specs.- Returns:
- This builder instance for chaining.
-
addInterceptor
Adds an application interceptor to this client.- Parameters:
interceptor- The interceptor to add.- Returns:
- This builder instance for chaining.
-
addNetworkInterceptor
Adds a network interceptor to this client.- Parameters:
interceptor- The interceptor to add.- Returns:
- This builder instance for chaining.
-
getBuilder
Returns the underlyingHttpd.Builderfor advanced configuration.- Returns:
- The raw builder.
-
sslContext
A convenience method to configure a customSSLContext. This method also sets a permissive trust manager and hostname verifier.- Parameters:
sslContext- The SSL context to use.- Returns:
- This builder instance for chaining.
-
build
Creates anHttpz.Clientwith the configured settings.- Returns:
- A new
Httpz.Clientinstance.
-
sslSocketFactory(SSLSocketFactory, X509TrustManager)instead.