java.lang.Object
org.miaixz.bus.http.Httpd
- All Implemented Interfaces:
Cloneable,NewCall.Factory,WebSocket.Factory
The core client for making HTTP requests and reading their responses. This class is designed to be efficient by
reusing connections with a connection pool. It is recommended to create a single, shared instance of
Httpd
and reuse it for all HTTP calls.
This class supports both synchronous and asynchronous calls. Asynchronous calls are executed on a background thread
pool, which is managed by a Dispatcher.
This class also supports advanced features like HTTP/2 and WebSockets.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA builder for configuring and creatingHttpdinstances. -
Constructor Summary
ConstructorsConstructorDescriptionHttpd()Constructs a newHttpdinstance with default settings.Httpd(Httpd.Builder builder) Constructs a newHttpdinstance configured by the givenHttpd.Builder. -
Method Summary
Modifier and TypeMethodDescriptionReturns the authenticator for handling challenges from origin servers.cache()Returns the cache used to store responses.intReturns the default timeout for complete calls in milliseconds.Returns the certificate pinner used to constrain trusted certificates.Returns the connection pool for managing and reusing connections.Returns the list of connection specs supported by this client.intReturns the default timeout for establishing a new connection in milliseconds.Returns the cookie jar used to manage HTTP cookies.Returns the dispatcher that manages asynchronous requests.dns()Returns the DNS service used to resolve hostnames.Returns the factory for creating event listeners.booleanReturns true if this client follows HTTP redirects.booleanReturns true if this client follows redirects from HTTPS to HTTP and vice versa.Returns the hostname verifier used for HTTPS connections.Returns the list of application interceptors.Returns the list of network interceptors.Returns a new builder that is a copy of this client's configuration.Prepares therequestto be executed at some point in the future.newWebSocket(Request request, WebSocketListener listener) Usesrequestto connect a new web socket.intReturns the WebSocket ping interval in milliseconds.List<org.miaixz.bus.core.net.Protocol> Returns the list of protocols supported by this client.proxy()Returns the configured HTTP proxy, or null if no proxy is configured.Returns the authenticator for handling challenges from proxy servers.Returns the proxy selector used to choose a proxy for a given URI.intReturns the default timeout for reading data from a connection in milliseconds.booleanReturns true if this client retries requests on connection failures.Returns the socket factory used for creating plain TCP connections.Returns the SSL socket factory used for creating HTTPS connections.intReturns the default timeout for writing data to a connection in milliseconds.
-
Constructor Details
-
Httpd
public Httpd()Constructs a newHttpdinstance with default settings. -
Httpd
Constructs a newHttpdinstance configured by the givenHttpd.Builder.- Parameters:
builder- The builder instance containing all configuration parameters.
-
-
Method Details
-
newCall
Prepares therequestto be executed at some point in the future.- Specified by:
newCallin interfaceNewCall.Factory- Parameters:
request- The HTTP request to execute.- Returns:
- a new
NewCallinstance that can be used to execute the request.
-
newWebSocket
Usesrequestto connect a new web socket.- Specified by:
newWebSocketin interfaceWebSocket.Factory- Parameters:
request- The WebSocket request object.listener- The WebSocket event listener.- Returns:
- a new
WebSocketinstance.
-
callTimeoutMillis
public int callTimeoutMillis()Returns the default timeout for complete calls in milliseconds.- Returns:
- the call timeout in milliseconds.
-
connectTimeoutMillis
public int connectTimeoutMillis()Returns the default timeout for establishing a new connection in milliseconds.- Returns:
- the connect timeout in milliseconds.
-
readTimeoutMillis
public int readTimeoutMillis()Returns the default timeout for reading data from a connection in milliseconds.- Returns:
- the read timeout in milliseconds.
-
writeTimeoutMillis
public int writeTimeoutMillis()Returns the default timeout for writing data to a connection in milliseconds.- Returns:
- the write timeout in milliseconds.
-
pingIntervalMillis
public int pingIntervalMillis()Returns the WebSocket ping interval in milliseconds.- Returns:
- the ping interval in milliseconds.
-
proxy
Returns the configured HTTP proxy, or null if no proxy is configured.- Returns:
- the proxy instance, which may be null.
-
proxySelector
Returns the proxy selector used to choose a proxy for a given URI.- Returns:
- the proxy selector.
-
cookieJar
Returns the cookie jar used to manage HTTP cookies.- Returns:
- the
CookieJarinstance.
-
cache
Returns the cache used to store responses.- Returns:
- the
Cacheinstance, which may be null.
-
dns
Returns the DNS service used to resolve hostnames.- Returns:
- the
DnsXinstance.
-
socketFactory
Returns the socket factory used for creating plain TCP connections.- Returns:
- the
SocketFactoryinstance.
-
sslSocketFactory
Returns the SSL socket factory used for creating HTTPS connections.- Returns:
- the
SSLSocketFactoryinstance.
-
hostnameVerifier
Returns the hostname verifier used for HTTPS connections.- Returns:
- the
HostnameVerifierinstance.
-
certificatePinner
Returns the certificate pinner used to constrain trusted certificates.- Returns:
- the
CertificatePinnerinstance.
-
authenticator
Returns the authenticator for handling challenges from origin servers.- Returns:
- the
Authenticatorinstance.
-
proxyAuthenticator
Returns the authenticator for handling challenges from proxy servers.- Returns:
- the
Authenticatorinstance.
-
connectionPool
Returns the connection pool for managing and reusing connections.- Returns:
- the
ConnectionPoolinstance.
-
followSslRedirects
public boolean followSslRedirects()Returns true if this client follows redirects from HTTPS to HTTP and vice versa.- Returns:
- true if SSL redirects are followed.
-
followRedirects
public boolean followRedirects()Returns true if this client follows HTTP redirects.- Returns:
- true if redirects are followed.
-
retryOnConnectionFailure
public boolean retryOnConnectionFailure()Returns true if this client retries requests on connection failures.- Returns:
- true if retry on connection failure is enabled.
-
dispatcher
Returns the dispatcher that manages asynchronous requests.- Returns:
- the
Dispatcherinstance.
-
protocols
Returns the list of protocols supported by this client.- Returns:
- an immutable list of protocols.
-
connectionSpecs
Returns the list of connection specs supported by this client.- Returns:
- an immutable list of connection specs.
-
interceptors
Returns the list of application interceptors.- Returns:
- an immutable list of interceptors.
-
networkInterceptors
Returns the list of network interceptors.- Returns:
- an immutable list of network interceptors.
-
eventListenerFactory
Returns the factory for creating event listeners.- Returns:
- the
EventListener.Factoryinstance.
-
newBuilder
Returns a new builder that is a copy of this client's configuration.- Returns:
- a new
Httpd.Builderinstance.
-