java.lang.Object
org.miaixz.bus.http.Httpd.Builder
- Enclosing class:
Httpd
A builder for configuring and creating
Httpd instances.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddInterceptor(Interceptor interceptor) Adds an application interceptor.addNetworkInterceptor(Interceptor interceptor) Adds a network interceptor.authenticator(Authenticator authenticator) Sets the authenticator used to respond to challenges from origin servers.build()Builds a newHttpdinstance with the configured settings.Sets the cache to be used to read and write cached responses.callTimeout(long timeout, TimeUnit unit) Sets the default timeout for complete calls.callTimeout(Duration duration) Sets the default timeout for complete calls.certificatePinner(CertificatePinner certificatePinner) Sets the certificate pinner that constrains which certificates are trusted.connectionPool(ConnectionPool connectionPool) Sets the connection pool used to recycle HTTP and HTTPS connections.connectionSpecs(List<ConnectionSuite> connectionSuites) Sets the connection specs for this client.connectTimeout(long timeout, TimeUnit unit) Sets the default connect timeout for new connections.connectTimeout(Duration duration) Sets the default connect timeout for new connections.Sets the cookie jar that will be used to manage cookies for all HTTP requests.dispatcher(Dispatcher dispatcher) Sets the dispatcher used to execute asynchronous requests.Sets the DNS service used to lookup IP addresses for hostnames.eventListener(EventListener eventListener) Sets the event listener for monitoring request lifecycle events.eventListenerFactory(EventListener.Factory eventListenerFactory) Sets the factory for creating event listeners.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.hostnameVerifier(HostnameVerifier hostnameVerifier) Sets the verifier used to confirm that response certificates apply to the requested hostnames for HTTPS connections.Returns a mutable list of the application interceptors that observe the full span of each call.Returns a mutable list of the network interceptors that observe a single network request and response.pingInterval(long interval, TimeUnit unit) Sets the WebSocket ping interval.pingInterval(Duration duration) Sets the WebSocket ping interval.Sets the protocols used for requests.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 selector that will be used to select the HTTP proxy for each request.readTimeout(long timeout, TimeUnit unit) Sets the default read timeout for new connections.readTimeout(Duration duration) Sets the default read timeout for new connections.retryOnConnectionFailure(boolean retryOnConnectionFailure) Configures this client to retry or not to retry when a connectivity problem is encountered.socketFactory(SocketFactory socketFactory) Sets the socket factory used to create connections.sslSocketFactory(SSLSocketFactory sslSocketFactory) Sets the SSL socket factory used to create HTTPS connections.sslSocketFactory(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager) Sets the SSL socket factory and trust manager used for HTTPS connections.writeTimeout(long timeout, TimeUnit unit) Sets the default write timeout for new connections.writeTimeout(Duration duration) Sets the default write timeout for new connections.
-
Constructor Details
-
Builder
public Builder()Default constructor which initializes with default settings.
-
-
Method Details
-
callTimeout
Sets the default timeout for complete calls. A value of 0 means no timeout.- Parameters:
timeout- the timeout value.unit- the time unit.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if the timeout value is invalid.
-
callTimeout
Sets the default timeout for complete calls. A value of 0 means no timeout.- Parameters:
duration- the timeout duration.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if the timeout value is invalid.
-
connectTimeout
Sets the default connect timeout for new connections. A value of 0 means no timeout.- Parameters:
timeout- the timeout value.unit- the time unit.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if the timeout value is invalid.
-
connectTimeout
Sets the default connect timeout for new connections. A value of 0 means no timeout.- Parameters:
duration- the timeout duration.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if the timeout value is invalid.
-
readTimeout
Sets the default read timeout for new connections. A value of 0 means no timeout.- Parameters:
timeout- the timeout value.unit- the time unit.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if the timeout value is invalid.- See Also:
-
readTimeout
Sets the default read timeout for new connections. A value of 0 means no timeout.- Parameters:
duration- the timeout duration.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if the timeout value is invalid.- See Also:
-
writeTimeout
Sets the default write timeout for new connections. A value of 0 means no timeout.- Parameters:
timeout- the timeout value.unit- the time unit.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if the timeout value is invalid.- See Also:
-
writeTimeout
Sets the default write timeout for new connections. A value of 0 means no timeout.- Parameters:
duration- the timeout duration.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if the timeout value is invalid.- See Also:
-
pingInterval
Sets the WebSocket ping interval. A value of 0 disables pings.- Parameters:
interval- the interval value.unit- the time unit.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if the interval value is invalid.
-
pingInterval
Sets the WebSocket ping interval. A value of 0 disables pings.- Parameters:
duration- the interval duration.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if the interval value is invalid.
-
proxy
Sets the HTTP proxy that will be used by connections created by this client.- Parameters:
proxy- the HTTP proxy.- Returns:
- this builder instance.
-
proxySelector
Sets the proxy selector that will be used to select the HTTP proxy for each request.- Parameters:
proxySelector- the proxy selector.- Returns:
- this builder instance.
- Throws:
NullPointerException- if proxySelector is null.
-
cookieJar
Sets the cookie jar that will be used to manage cookies for all HTTP requests.- Parameters:
cookieJar- the cookie jar.- Returns:
- this builder instance.
- Throws:
NullPointerException- if cookieJar is null.
-
cache
Sets the cache to be used to read and write cached responses.- Parameters:
cache- the cache instance.- Returns:
- this builder instance.
-
dns
Sets the DNS service used to lookup IP addresses for hostnames.- Parameters:
dns- the DNS service.- Returns:
- this builder instance.
- Throws:
NullPointerException- if dns is null.
-
socketFactory
Sets the socket factory used to create connections.- Parameters:
socketFactory- the socket factory.- Returns:
- this builder instance.
- Throws:
NullPointerException- if socketFactory is null.IllegalArgumentException- if socketFactory is an instance ofSSLSocketFactory.
-
sslSocketFactory
Sets the SSL socket factory used to create HTTPS connections.- Parameters:
sslSocketFactory- the SSL socket factory.- Returns:
- this builder instance.
- Throws:
NullPointerException- if sslSocketFactory is null.
-
sslSocketFactory
public Httpd.Builder sslSocketFactory(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager) Sets the SSL socket factory and trust manager used for HTTPS connections.Most applications should not call this method, and instead use the system defaults.
- Parameters:
sslSocketFactory- the SSL socket factory.trustManager- the X.509 trust manager.- Returns:
- this builder instance.
- Throws:
NullPointerException- if sslSocketFactory or trustManager is null.
-
hostnameVerifier
Sets the verifier used to confirm that response certificates apply to the requested hostnames for HTTPS connections.- Parameters:
hostnameVerifier- the hostname verifier.- Returns:
- this builder instance.
- Throws:
NullPointerException- if hostnameVerifier is null.
-
certificatePinner
Sets the certificate pinner that constrains which certificates are trusted.- Parameters:
certificatePinner- the certificate pinner.- Returns:
- this builder instance.
- Throws:
NullPointerException- if certificatePinner is null.
-
authenticator
Sets the authenticator used to respond to challenges from origin servers.- Parameters:
authenticator- the authenticator.- Returns:
- this builder instance.
- Throws:
NullPointerException- if authenticator is null.
-
proxyAuthenticator
Sets the authenticator used to respond to challenges from proxy servers.- Parameters:
proxyAuthenticator- the proxy authenticator.- Returns:
- this builder instance.
- Throws:
NullPointerException- if proxyAuthenticator is null.
-
connectionPool
Sets the connection pool used to recycle HTTP and HTTPS connections.- Parameters:
connectionPool- the connection pool.- Returns:
- this builder instance.
- Throws:
NullPointerException- if connectionPool is null.
-
followSslRedirects
Configures this client to follow redirects from HTTPS to HTTP and from HTTP to HTTPS.- Parameters:
followProtocolRedirects- whether to follow SSL redirects.- Returns:
- this builder instance.
-
followRedirects
Configures this client to follow redirects.- Parameters:
followRedirects- whether to follow HTTP redirects.- Returns:
- this builder instance.
-
retryOnConnectionFailure
Configures this client to retry or not to retry when a connectivity problem is encountered.- Parameters:
retryOnConnectionFailure- whether to retry on connection failure.- Returns:
- this builder instance.
-
dispatcher
Sets the dispatcher used to execute asynchronous requests.- Parameters:
dispatcher- the dispatcher.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if dispatcher is null.
-
protocols
Sets the protocols used for requests.- Parameters:
protocols- the list of protocols.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if the protocols list is invalid.
-
connectionSpecs
Sets the connection specs for this client.- Parameters:
connectionSuites- the list of connection specs.- Returns:
- this builder instance.
-
interceptors
Returns a mutable list of the application interceptors that observe the full span of each call.- Returns:
- the list of application interceptors.
-
addInterceptor
Adds an application interceptor.- Parameters:
interceptor- the application interceptor.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if interceptor is null.
-
networkInterceptors
Returns a mutable list of the network interceptors that observe a single network request and response.- Returns:
- the list of network interceptors.
-
addNetworkInterceptor
Adds a network interceptor.- Parameters:
interceptor- the network interceptor.- Returns:
- this builder instance.
- Throws:
IllegalArgumentException- if interceptor is null.
-
eventListener
Sets the event listener for monitoring request lifecycle events.- Parameters:
eventListener- the event listener.- Returns:
- this builder instance.
- Throws:
NullPointerException- if eventListener is null.
-
eventListenerFactory
Sets the factory for creating event listeners.- Parameters:
eventListenerFactory- the event listener factory.- Returns:
- this builder instance.
- Throws:
NullPointerException- if eventListenerFactory is null.
-
build
Builds a newHttpdinstance with the configured settings.- Returns:
- a new
Httpdinstance.
-