public class HttpClient extends Object implements Measured
It allows you to make requests to HTTP servers, and a single client can make requests to any server.
It also allows you to open WebSockets to servers.
The client can also pool HTTP connections.
For pooling to occur, keep-alive must be true on the HttpClientOptions
(default is true).
In this case connections will be pooled and re-used if there are pending HTTP requests waiting to get a connection,
otherwise they will be closed.
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 also supports pipe-lining of requests. Pipe-lining means another request is sent on the same connection before the response from the preceding one has returned. Pipe-lining is not appropriate for all requests.
To enable pipe-lining, it must be enabled on the HttpClientOptions
(default is false).
When pipe-lining is enabled the connection will be automatically closed when all in-flight responses have returned and there are no outstanding pending requests to write.
The client is designed to be reused between requests.
NOTE: This class has been automatically generated from theoriginal
non RX-ified interface using Vert.x codegen.Modifier and Type | Field and Description |
---|---|
static io.vertx.lang.rx.TypeArg<HttpClient> |
__TYPE_ARG |
Constructor and Description |
---|
HttpClient(HttpClient delegate) |
HttpClient(Object delegate) |
Modifier and Type | Method and Description |
---|---|
Completable |
close()
Close the client.
|
HttpClient |
connectionHandler(Handler<HttpConnection> handler)
Set a connection handler for the client.
|
boolean |
equals(Object o) |
HttpClient |
getDelegate() |
int |
hashCode() |
boolean |
isMetricsEnabled()
Whether the metrics are enabled for this measured object
|
static HttpClient |
newInstance(HttpClient arg) |
HttpClient |
redirectHandler(java.util.function.Function<HttpClientResponse,Single<RequestOptions>> handler)
Set a redirect handler for the http client.
|
Single<HttpClientRequest> |
request(HttpMethod method,
int port,
String host,
String requestURI)
Create an HTTP request to send to the server at the
host and port . |
Single<HttpClientRequest> |
request(HttpMethod method,
String requestURI)
Create an HTTP request to send to the server at the default host and port.
|
Single<HttpClientRequest> |
request(HttpMethod method,
String host,
String requestURI)
Create an HTTP request to send to the server at the
host and default port. |
Single<HttpClientRequest> |
request(RequestOptions options)
Create an HTTP request to send to the server.
|
Completable |
rxClose()
Close the client.
|
Single<HttpClientRequest> |
rxRequest(HttpMethod method,
int port,
String host,
String requestURI)
Create an HTTP request to send to the server at the
host and port . |
Single<HttpClientRequest> |
rxRequest(HttpMethod method,
String requestURI)
Create an HTTP request to send to the server at the default host and port.
|
Single<HttpClientRequest> |
rxRequest(HttpMethod method,
String host,
String requestURI)
Create an HTTP request to send to the server at the
host and default port. |
Single<HttpClientRequest> |
rxRequest(RequestOptions options)
Create an HTTP request to send to the server.
|
Single<WebSocket> |
rxWebSocket(int port,
String host,
String requestURI)
Connect a WebSocket to the specified port, host and relative request URI
|
Single<WebSocket> |
rxWebSocket(String requestURI)
Connect a WebSocket at the relative request URI using the default host and port
|
Single<WebSocket> |
rxWebSocket(String host,
String requestURI)
Connect a WebSocket to the host and relative request URI and default port
|
Single<WebSocket> |
rxWebSocket(WebSocketConnectOptions options)
Connect a WebSocket with the specified options.
|
Single<WebSocket> |
rxWebSocketAbs(String url,
MultiMap headers,
WebsocketVersion version,
List<String> subProtocols)
Connect a WebSocket with the specified absolute url, with the specified headers, using
the specified version of WebSockets, and the specified WebSocket sub protocols.
|
String |
toString() |
Single<WebSocket> |
webSocket(int port,
String host,
String requestURI)
Connect a WebSocket to the specified port, host and relative request URI
|
Single<WebSocket> |
webSocket(String requestURI)
Connect a WebSocket at the relative request URI using the default host and port
|
Single<WebSocket> |
webSocket(String host,
String requestURI)
Connect a WebSocket to the host and relative request URI and default port
|
Single<WebSocket> |
webSocket(WebSocketConnectOptions options)
Connect a WebSocket with the specified options.
|
Single<WebSocket> |
webSocketAbs(String url,
MultiMap headers,
WebsocketVersion version,
List<String> subProtocols)
Connect a WebSocket with the specified absolute url, with the specified headers, using
the specified version of WebSockets, and the specified WebSocket sub protocols.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
newInstance
public static final io.vertx.lang.rx.TypeArg<HttpClient> __TYPE_ARG
public HttpClient(HttpClient delegate)
public HttpClient(Object delegate)
public HttpClient getDelegate()
getDelegate
in interface Measured
public boolean isMetricsEnabled()
isMetricsEnabled
in interface Measured
true
if metrics are enabledpublic Single<HttpClientRequest> request(RequestOptions options)
handler
is called when the request is ready to be sent.options
- the request optionspublic Single<HttpClientRequest> rxRequest(RequestOptions options)
handler
is called when the request is ready to be sent.options
- the request optionspublic Single<HttpClientRequest> request(HttpMethod method, int port, String host, String requestURI)
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 URIpublic Single<HttpClientRequest> rxRequest(HttpMethod method, int port, String host, String requestURI)
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 URIpublic Single<HttpClientRequest> request(HttpMethod method, String host, String requestURI)
host
and default port. The handler
is called when the request is ready to be sent.method
- the HTTP methodhost
- the hostrequestURI
- the relative URIpublic Single<HttpClientRequest> rxRequest(HttpMethod method, String host, String requestURI)
host
and default port. The handler
is called when the request is ready to be sent.method
- the HTTP methodhost
- the hostrequestURI
- the relative URIpublic Single<HttpClientRequest> request(HttpMethod method, String requestURI)
handler
is called when the request is ready to be sent.method
- the HTTP methodrequestURI
- the relative URIpublic Single<HttpClientRequest> rxRequest(HttpMethod method, String requestURI)
handler
is called when the request is ready to be sent.method
- the HTTP methodrequestURI
- the relative URIpublic Single<WebSocket> webSocket(int port, String host, String requestURI)
port
- the porthost
- the hostrequestURI
- the relative URIpublic Single<WebSocket> rxWebSocket(int port, String host, String requestURI)
port
- the porthost
- the hostrequestURI
- the relative URIpublic Single<WebSocket> webSocket(String host, String requestURI)
host
- the hostrequestURI
- the relative URIpublic Single<WebSocket> rxWebSocket(String host, String requestURI)
host
- the hostrequestURI
- the relative URIpublic Single<WebSocket> webSocket(String requestURI)
requestURI
- the relative URIpublic Single<WebSocket> rxWebSocket(String requestURI)
requestURI
- the relative URIpublic Single<WebSocket> webSocket(WebSocketConnectOptions options)
options
- the request optionspublic Single<WebSocket> rxWebSocket(WebSocketConnectOptions options)
options
- the request optionspublic Single<WebSocket> webSocketAbs(String url, MultiMap headers, WebsocketVersion version, List<String> subProtocols)
url
- the absolute urlheaders
- the headersversion
- the WebSocket versionsubProtocols
- the subprotocols to usepublic Single<WebSocket> rxWebSocketAbs(String url, MultiMap headers, WebsocketVersion version, List<String> subProtocols)
url
- the absolute urlheaders
- the headersversion
- the WebSocket versionsubProtocols
- the subprotocols to usepublic HttpClient connectionHandler(Handler<HttpConnection> handler)
handler
- public HttpClient redirectHandler(java.util.function.Function<HttpClientResponse,Single<RequestOptions>> handler)
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
is returned, the client will send this new request
The handler must return a Future
unsent so the client can further configure it and send it.
handler
- the new redirect handlerpublic Completable close()
public Completable rxClose()
public static HttpClient newInstance(HttpClient arg)
Copyright © 2022 Eclipse. All rights reserved.