public interface HttpClient extends Measured
It allows you to make requests to HTTP servers, and a single client can make requests to any server.
This gives the benefits of keep alive when the client is loaded but means we don't keep connections hanging around unnecessarily when there would be no benefits anyway.
The client is designed to be reused between requests.
Modifier and Type | Method and Description |
---|---|
Future<Void> |
close()
Like
close(Handler) but returns a Future of the asynchronous result |
void |
close(Handler<AsyncResult<Void>> handler)
Close the client.
|
HttpClient |
connectionHandler(Handler<HttpConnection> handler)
Deprecated.
instead use
HttpClientBuilder.withConnectHandler(Handler) |
java.util.function.Function<HttpClientResponse,Future<RequestOptions>> |
redirectHandler()
Deprecated.
|
HttpClient |
redirectHandler(java.util.function.Function<HttpClientResponse,Future<RequestOptions>> handler)
Deprecated.
instead use
HttpClientBuilder.withRedirectHandler(Function) |
default Future<HttpClientRequest> |
request(HttpMethod method,
int port,
String host,
String requestURI)
Like
request(HttpMethod, int, String, String, Handler) but returns a Future of the asynchronous result |
void |
request(HttpMethod method,
int port,
String host,
String requestURI,
Handler<AsyncResult<HttpClientRequest>> handler)
Create an HTTP request to send to the server at the
host and port . |
default Future<HttpClientRequest> |
request(HttpMethod method,
String requestURI)
Like
request(HttpMethod, String, Handler) but returns a Future of the asynchronous result |
void |
request(HttpMethod method,
String requestURI,
Handler<AsyncResult<HttpClientRequest>> handler)
Create an HTTP request to send to the server at the default host and port.
|
default Future<HttpClientRequest> |
request(HttpMethod method,
String host,
String requestURI)
Like
request(HttpMethod, String, String, Handler) but returns a Future of the asynchronous result |
void |
request(HttpMethod method,
String host,
String requestURI,
Handler<AsyncResult<HttpClientRequest>> handler)
Create an HTTP request to send to the server at the
host and default port. |
Future<HttpClientRequest> |
request(RequestOptions options)
Like
request(RequestOptions, Handler) but returns a Future of the asynchronous result |
void |
request(RequestOptions options,
Handler<AsyncResult<HttpClientRequest>> handler)
Create an HTTP request to send to the server.
|
default Future<Boolean> |
updateSSLOptions(SSLOptions options)
Update the client with new SSL
options , the update happens if the options object is valid and different
from the existing options object. |
Future<Boolean> |
updateSSLOptions(SSLOptions options,
boolean force)
Update the client with new SSL
options , the update happens if the options object is valid and different
from the existing options object. |
default void |
updateSSLOptions(SSLOptions options,
boolean force,
Handler<AsyncResult<Boolean>> handler)
Like
updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update
happened (or has failed). |
default void |
updateSSLOptions(SSLOptions options,
Handler<AsyncResult<Boolean>> handler)
Like
updateSSLOptions(SSLOptions) but supplying a handler that will be called when the update
happened (or has failed). |
Future<WebSocket> |
webSocket(int port,
String host,
String requestURI)
Deprecated.
instead use
WebSocketClient.connect(int, String, String) |
void |
webSocket(int port,
String host,
String requestURI,
Handler<AsyncResult<WebSocket>> handler)
Deprecated.
|
Future<WebSocket> |
webSocket(String requestURI)
Deprecated.
instead use
WebSocketClient.connect(int, String, String) |
void |
webSocket(String requestURI,
Handler<AsyncResult<WebSocket>> handler)
Deprecated.
|
Future<WebSocket> |
webSocket(String host,
String requestURI)
Deprecated.
instead use
WebSocketClient.connect(int, String, String) |
void |
webSocket(String host,
String requestURI,
Handler<AsyncResult<WebSocket>> handler)
Deprecated.
|
Future<WebSocket> |
webSocket(WebSocketConnectOptions options)
Deprecated.
instead use
WebSocketClient.connect(WebSocketConnectOptions) |
void |
webSocket(WebSocketConnectOptions options,
Handler<AsyncResult<WebSocket>> handler)
Deprecated.
|
Future<WebSocket> |
webSocketAbs(String url,
MultiMap headers,
WebsocketVersion version,
List<String> subProtocols)
Deprecated.
instead use
WebSocketClient.connect(WebSocketConnectOptions) |
void |
webSocketAbs(String url,
MultiMap headers,
WebsocketVersion version,
List<String> subProtocols,
Handler<AsyncResult<WebSocket>> handler)
Deprecated.
|
isMetricsEnabled
void request(RequestOptions options, Handler<AsyncResult<HttpClientRequest>> handler)
handler
is called when the request is ready to be sent.options
- the request optionshandler
- the handler called when the request is ready to be sentFuture<HttpClientRequest> request(RequestOptions options)
request(RequestOptions, Handler)
but returns a Future
of the asynchronous resultvoid request(HttpMethod method, int port, String host, String requestURI, Handler<AsyncResult<HttpClientRequest>> handler)
host
and port
. The handler
is called when the request is ready to be sent.method
- the HTTP methodport
- the porthost
- the hostrequestURI
- the relative URIhandler
- the handler called when the request is ready to be sentdefault Future<HttpClientRequest> request(HttpMethod method, int port, String host, String requestURI)
request(HttpMethod, int, String, String, Handler)
but returns a Future
of the asynchronous resultvoid request(HttpMethod method, String host, String requestURI, Handler<AsyncResult<HttpClientRequest>> handler)
host
and default port. The handler
is called when the request is ready to be sent.method
- the HTTP methodhost
- the hostrequestURI
- the relative URIhandler
- the handler called when the request is ready to be sentdefault Future<HttpClientRequest> request(HttpMethod method, String host, String requestURI)
request(HttpMethod, String, String, Handler)
but returns a Future
of the asynchronous resultvoid request(HttpMethod method, String requestURI, Handler<AsyncResult<HttpClientRequest>> handler)
handler
is called when the request is ready to be sent.method
- the HTTP methodrequestURI
- the relative URIhandler
- the handler called when the request is ready to be sentdefault Future<HttpClientRequest> request(HttpMethod method, String requestURI)
request(HttpMethod, String, Handler)
but returns a Future
of the asynchronous result@Deprecated void webSocket(int port, String host, String requestURI, Handler<AsyncResult<WebSocket>> handler)
WebSocketClient.connect(int, String, String, Handler)
port
- the porthost
- the hostrequestURI
- the relative URIhandler
- handler that will be called with the WebSocket when connected@Deprecated Future<WebSocket> webSocket(int port, String host, String requestURI)
WebSocketClient.connect(int, String, String)
webSocket(int, String, String, Handler)
but returns a Future
of the asynchronous result@Deprecated void webSocket(String host, String requestURI, Handler<AsyncResult<WebSocket>> handler)
WebSocketClient.connect(int, String, String, Handler)
host
- the hostrequestURI
- the relative URIhandler
- handler that will be called with the WebSocket when connected@Deprecated Future<WebSocket> webSocket(String host, String requestURI)
WebSocketClient.connect(int, String, String)
webSocket(String, String, Handler)
but returns a Future
of the asynchronous result@Deprecated void webSocket(String requestURI, Handler<AsyncResult<WebSocket>> handler)
WebSocketClient.connect(int, String, String, Handler)
requestURI
- the relative URIhandler
- handler that will be called with the WebSocket when connected@Deprecated Future<WebSocket> webSocket(String requestURI)
WebSocketClient.connect(int, String, String)
webSocket(String, Handler)
but returns a Future
of the asynchronous result@Deprecated void webSocket(WebSocketConnectOptions options, Handler<AsyncResult<WebSocket>> handler)
WebSocketClient.connect(WebSocketConnectOptions, Handler)
options
- the request options@Deprecated Future<WebSocket> webSocket(WebSocketConnectOptions options)
WebSocketClient.connect(WebSocketConnectOptions)
webSocket(WebSocketConnectOptions, Handler)
but returns a Future
of the asynchronous result@Deprecated void webSocketAbs(String url, MultiMap headers, WebsocketVersion version, List<String> subProtocols, Handler<AsyncResult<WebSocket>> handler)
WebSocketClient.connect(WebSocketConnectOptions, Handler)
url
- the absolute urlheaders
- the headersversion
- the WebSocket versionsubProtocols
- the subprotocols to usehandler
- handler that will be called if WebSocket connection fails@Deprecated Future<WebSocket> webSocketAbs(String url, MultiMap headers, WebsocketVersion version, List<String> subProtocols)
WebSocketClient.connect(WebSocketConnectOptions)
webSocketAbs(String, MultiMap, WebsocketVersion, List, Handler)
but returns a Future
of the asynchronous resultdefault Future<Boolean> updateSSLOptions(SSLOptions options)
Update the client with new SSL options
, the update happens if the options object is valid and different
from the existing options object.
The boolean succeeded future result indicates whether the update occurred.
options
- the new SSL optionsdefault void updateSSLOptions(SSLOptions options, Handler<AsyncResult<Boolean>> handler)
updateSSLOptions(SSLOptions)
but supplying a handler that will be called when the update
happened (or has failed).options
- the new SSL optionshandler
- the update handlerFuture<Boolean> updateSSLOptions(SSLOptions options, boolean force)
Update the client with new SSL options
, the update happens if the options object is valid and different
from the existing options object.
The options
object is compared using its equals
method against the existing options to prevent
an update when the objects are equals since loading options can be costly, this can happen for share TCP servers.
When object are equals, setting force
to true
forces the update.
The boolean succeeded future result indicates whether the update occurred.
options
- the new SSL optionsforce
- force the update when options are equalsdefault void updateSSLOptions(SSLOptions options, boolean force, Handler<AsyncResult<Boolean>> handler)
updateSSLOptions(SSLOptions)
but supplying a handler that will be called when the update
happened (or has failed).options
- the new SSL optionsforce
- force the update when options are equalshandler
- the update handler@Deprecated HttpClient connectionHandler(Handler<HttpConnection> handler)
HttpClientBuilder.withConnectHandler(Handler)
@Deprecated HttpClient redirectHandler(java.util.function.Function<HttpClientResponse,Future<RequestOptions>> handler)
HttpClientBuilder.withRedirectHandler(Function)
The redirect handler is called when a 3xx
response is received and the request is configured to
follow redirects with HttpClientRequest.setFollowRedirects(boolean)
.
The redirect handler is passed the HttpClientResponse
, it can return an HttpClientRequest
or null
.
Future<HttpClientRequest>
is returned, the client will send this new request
The handler must return a Future<HttpClientRequest>
unsent so the client can further configure it and send it.
handler
- the new redirect handler@Deprecated java.util.function.Function<HttpClientResponse,Future<RequestOptions>> redirectHandler()
void close(Handler<AsyncResult<Void>> handler)
Future<Void> close()
close(Handler)
but returns a Future
of the asynchronous resultCopyright © 2024 Eclipse. All rights reserved.