Top Description Inners Fields Constructors Methods
io.vertx.core.http.impl

public Class HttpClientImpl

extends HttpClientBase
implements HttpClientInternal, MetricsProvider, Closeable
Class Inheritance
All Implemented Interfaces
io.vertx.core.Closeable, io.vertx.core.spi.metrics.MetricsProvider, io.vertx.core.metrics.Measured, io.vertx.core.http.impl.HttpClientInternal, io.vertx.core.http.HttpClient
Imports
io.vertx.core.AsyncResult, .Closeable, .Future, .Handler, .MultiMap, .Promise, io.vertx.core.http.*, io.vertx.core.impl.CloseFuture, .ContextInternal, .VertxInternal, io.vertx.core.impl.future.PromiseInternal, io.vertx.core.net.*, io.vertx.core.net.impl.pool.ConnectionManager, .Endpoint, .EndpointProvider, .Lease, io.vertx.core.spi.metrics.ClientMetrics, .MetricsProvider, java.lang.ref.WeakReference, java.net.URI, java.util.Base64, .Objects, java.util.function.Consumer, .Function, java.util.regex.Pattern

This class is thread-safe.
Author
Tim Fox

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
HttpClientImpl.PoolChecker

A weak ref to the client so it can be finalized.

Field Summary

Modifier and TypeField and Description
private static final Pattern
private volatile Handler<HttpConnection>
private static final Function<HttpClientResponse, Future<RequestOptions>>
private static final Consumer<Endpoint<Lease<HttpClientConnection>>>
private final ConnectionManager<EndpointKey, Lease<HttpClientConnection>>
private final PoolOptions
private volatile Function<HttpClientResponse, Future<RequestOptions>>
private long
Inherited from io.vertx.core.http.impl.HttpClientBase:
closeFuturemetricsnetClientoptionsuseH2UniformStreamByteDistributorvertx

Constructor Summary

AccessConstructor and Description
public
HttpClientImpl(VertxInternal vertx, HttpClientOptions options, PoolOptions poolOptions, CloseFuture closeFuture)

Method Summary

Modifier and TypeMethod and Description
private void
private void
public void
close(Promise<Void>
the promise to signal when close has completed
completion
)

Overrides io.vertx.core.http.impl.HttpClientBase.close.

Implements io.vertx.core.Closeable.close.

Close this resource, the completion promise must be notified when the operation has completed.

public Future<HttpClientConnection>
connect(SocketAddress
the server address
server
)

Overrides default io.vertx.core.http.impl.HttpClientInternal.connect.

Connect to a server.

public Future<HttpClientConnection>
connect(SocketAddress
the server address
server
,
SocketAddress
the peer
peer
)

Implements io.vertx.core.http.impl.HttpClientInternal.connect.

Connect to a server.

public HttpClient
connectionHandler(Handler<HttpConnection> handler)

Implements io.vertx.core.http.HttpClient.connectionHandler.

Set a connection handler for the client.

public Handler<HttpConnection>
pack-priv Future<HttpClientRequest>
private HttpClientRequest
private void
private void
doRequest(HttpMethod method, SocketAddress server, String host, int port, Boolean useSSL, String requestURI, MultiMap headers, String traceOperation, long connectTimeout, long idleTimeout, Boolean followRedirects, ProxyOptions proxyOptions, EndpointKey key, PromiseInternal<HttpClientRequest> requestPromise)

private ConnectionManager<EndpointKey, Lease<HttpClientConnection>>
public NetClient
private static SocketAddress
peerAddress(SocketAddress remoteAddress, final String peerHost, int peerPort)

public HttpClient
redirectHandler(Function<HttpClientResponse, Future<RequestOptions>>
the new redirect handler
handler
)

Implements io.vertx.core.http.HttpClient.redirectHandler.

Set a redirect handler for the http client.

public Function<HttpClientResponse, Future<RequestOptions>>
public void
request(RequestOptions
the request options
options
,
Handler<AsyncResult<HttpClientRequest>>
the handler called when the request is ready to be sent
handler
)

Implements io.vertx.core.http.HttpClient.request.

Create an HTTP request to send to the server.

public Future<HttpClientRequest>
request(RequestOptions options)

Implements io.vertx.core.http.HttpClient.request.

Like request(RequestOptions, Handler) but returns a Future of the asynchronous result

public void
request(HttpMethod
the HTTP method
method
,
int
the port
port
,
String
the host
host
,
String
the relative URI
requestURI
,
Handler<AsyncResult<HttpClientRequest>>
the handler called when the request is ready to be sent
handler
)

Implements io.vertx.core.http.HttpClient.request.

Create an HTTP request to send to the server at the host and port.

public Future<HttpClientRequest>
request(HttpMethod method, int port, String host, String requestURI)

Overrides default io.vertx.core.http.HttpClient.request.

Like request(HttpMethod, int, String, String, Handler) but returns a Future of the asynchronous result

public void
request(HttpMethod
the HTTP method
method
,
String
the host
host
,
String
the relative URI
requestURI
,
Handler<AsyncResult<HttpClientRequest>>
the handler called when the request is ready to be sent
handler
)

Implements io.vertx.core.http.HttpClient.request.

Create an HTTP request to send to the server at the host and default port.

public Future<HttpClientRequest>
request(HttpMethod method, String host, String requestURI)

Overrides default io.vertx.core.http.HttpClient.request.

Like request(HttpMethod, String, String, Handler) but returns a Future of the asynchronous result

public void
request(HttpMethod
the HTTP method
method
,
String
the relative URI
requestURI
,
Handler<AsyncResult<HttpClientRequest>>
the handler called when the request is ready to be sent
handler
)

Implements io.vertx.core.http.HttpClient.request.

Create an HTTP request to send to the server at the default host and port.

public Future<HttpClientRequest>
request(HttpMethod method, String requestURI)

Overrides default io.vertx.core.http.HttpClient.request.

Like request(HttpMethod, String, Handler) but returns a Future of the asynchronous result

Inherited from io.vertx.core.http.impl.HttpClientBase:
closeclosecontextProvidergetHostgetMetricsgetPortisMetricsEnabledmetricsoptionsproxyFilterresolveProxyOptionsupdateSSLOptionsvertxwebSocketwebSocketwebSocketwebSocketwebSocketwebSocketwebSocketwebSocketwebSocketAbswebSocketAbs

Field Detail

ABS_URI_START_PATTERNback to summary
private static final Pattern ABS_URI_START_PATTERN
connectionHandlerback to summary
private volatile Handler<HttpConnection> connectionHandler
DEFAULT_HANDLERback to summary
private static final Function<HttpClientResponse, Future<RequestOptions>> DEFAULT_HANDLER
EXPIRED_CHECKERback to summary
private static final Consumer<Endpoint<Lease<HttpClientConnection>>> EXPIRED_CHECKER
httpCMback to summary
private final ConnectionManager<EndpointKey, Lease<HttpClientConnection>> httpCM
poolOptionsback to summary
private final PoolOptions poolOptions
redirectHandlerback to summary
private volatile Function<HttpClientResponse, Future<RequestOptions>> redirectHandler
timerIDback to summary
private long timerID

Constructor Detail

HttpClientImplback to summary
public HttpClientImpl(VertxInternal vertx, HttpClientOptions options, PoolOptions poolOptions, CloseFuture closeFuture)

Method Detail

checkClosedback to summary
private void checkClosed()
checkExpiredback to summary
private void checkExpired(Handler<Long> checker)
closeback to summary
public void close(Promise<Void> completion)

Overrides io.vertx.core.http.impl.HttpClientBase.close.

Implements io.vertx.core.Closeable.close.

Doc from io.vertx.core.Closeable.close.

Close this resource, the completion promise must be notified when the operation has completed.

Parameters
completion:Promise<Void>

the promise to signal when close has completed

Annotations
@Override
connectback to summary
public Future<HttpClientConnection> connect(SocketAddress server)

Overrides default io.vertx.core.http.impl.HttpClientInternal.connect.

Connect to a server.

Parameters
server:SocketAddress

Doc from io.vertx.core.http.impl.HttpClientInternal.connect.

the server address

connectback to summary
public Future<HttpClientConnection> connect(SocketAddress server, SocketAddress peer)

Implements io.vertx.core.http.impl.HttpClientInternal.connect.

Connect to a server.

Parameters
server:SocketAddress

Doc from io.vertx.core.http.impl.HttpClientInternal.connect.

the server address

peer:SocketAddress

Doc from io.vertx.core.http.impl.HttpClientInternal.connect.

the peer

connectionHandlerback to summary
public HttpClient connectionHandler(Handler<HttpConnection> handler)

Implements io.vertx.core.http.HttpClient.connectionHandler.

Doc from io.vertx.core.http.HttpClient.connectionHandler.

Set a connection handler for the client. This handler is called when a new connection is established.

Returns:HttpClient

a reference to this, so the API can be used fluently

Annotations
@Override
connectionHandlerback to summary
public Handler<HttpConnection> connectionHandler()
createRequestback to summary
pack-priv Future<HttpClientRequest> createRequest(HttpClientConnection conn, ContextInternal context)
createRequestback to summary
private HttpClientRequest createRequest(HttpClientStream stream)
doRequestback to summary
private void doRequest(RequestOptions request, PromiseInternal<HttpClientRequest> promise)
doRequestback to summary
private void doRequest(HttpMethod method, SocketAddress server, String host, int port, Boolean useSSL, String requestURI, MultiMap headers, String traceOperation, long connectTimeout, long idleTimeout, Boolean followRedirects, ProxyOptions proxyOptions, EndpointKey key, PromiseInternal<HttpClientRequest> requestPromise)
httpConnectionManagerback to summary
private ConnectionManager<EndpointKey, Lease<HttpClientConnection>> httpConnectionManager()
netClientback to summary
public NetClient netClient()

Overrides io.vertx.core.http.impl.HttpClientBase.netClient.

peerAddressback to summary
private static SocketAddress peerAddress(SocketAddress remoteAddress, final String peerHost, int peerPort)
redirectHandlerback to summary
public HttpClient redirectHandler(Function<HttpClientResponse, Future<RequestOptions>> handler)

Implements io.vertx.core.http.HttpClient.redirectHandler.

Doc from io.vertx.core.http.HttpClient.redirectHandler.

Set a redirect handler for the http client.

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.

  • when null is returned, the original response is processed by the original request response handler
  • when a new Future<HttpClientRequest> is returned, the client will send this new request
The new request will get a copy of the previous request headers unless headers are set. In this case, the client assumes that the redirect handler exclusively managers the headers of the new request.

The handler must return a Future<HttpClientRequest> unsent so the client can further configure it and send it.

Parameters
handler:Function<HttpClientResponse, Future<RequestOptions>>

the new redirect handler

Returns:HttpClient

a reference to this, so the API can be used fluently

Annotations
@Override
redirectHandlerback to summary
public Function<HttpClientResponse, Future<RequestOptions>> redirectHandler()

Implements io.vertx.core.http.HttpClient.redirectHandler.

Returns:Function<HttpClientResponse, Future<RequestOptions>>

Doc from io.vertx.core.http.HttpClient.redirectHandler.

the current redirect handler.

Annotations
@Override
requestback to summary
public void request(RequestOptions options, Handler<AsyncResult<HttpClientRequest>> handler)

Implements io.vertx.core.http.HttpClient.request.

Doc from io.vertx.core.http.HttpClient.request.

Create an HTTP request to send to the server. The handler is called when the request is ready to be sent.

Parameters
options:RequestOptions

the request options

handler:Handler<AsyncResult<HttpClientRequest>>

the handler called when the request is ready to be sent

Annotations
@Override
requestback to summary
public Future<HttpClientRequest> request(RequestOptions options)

Implements io.vertx.core.http.HttpClient.request.

Doc from io.vertx.core.http.HttpClient.request.

Like request(RequestOptions, Handler) but returns a Future of the asynchronous result

Annotations
@Override
requestback to summary
public void request(HttpMethod method, int port, String host, String requestURI, Handler<AsyncResult<HttpClientRequest>> handler)

Implements io.vertx.core.http.HttpClient.request.

Doc from io.vertx.core.http.HttpClient.request.

Create an HTTP request to send to the server at the host and port. The handler is called when the request is ready to be sent.

Parameters
method:HttpMethod

the HTTP method

port:int

the port

host:String

the host

requestURI:String

the relative URI

handler:Handler<AsyncResult<HttpClientRequest>>

the handler called when the request is ready to be sent

Annotations
@Override
requestback to summary
public Future<HttpClientRequest> request(HttpMethod method, int port, String host, String requestURI)

Overrides default io.vertx.core.http.HttpClient.request.

Doc from io.vertx.core.http.HttpClient.request.

Like request(HttpMethod, int, String, String, Handler) but returns a Future of the asynchronous result

Annotations
@Override
requestback to summary
public void request(HttpMethod method, String host, String requestURI, Handler<AsyncResult<HttpClientRequest>> handler)

Implements io.vertx.core.http.HttpClient.request.

Doc from io.vertx.core.http.HttpClient.request.

Create an HTTP request to send to the server at the host and default port. The handler is called when the request is ready to be sent.

Parameters
method:HttpMethod

the HTTP method

host:String

the host

requestURI:String

the relative URI

handler:Handler<AsyncResult<HttpClientRequest>>

the handler called when the request is ready to be sent

Annotations
@Override
requestback to summary
public Future<HttpClientRequest> request(HttpMethod method, String host, String requestURI)

Overrides default io.vertx.core.http.HttpClient.request.

Doc from io.vertx.core.http.HttpClient.request.

Like request(HttpMethod, String, String, Handler) but returns a Future of the asynchronous result

Annotations
@Override
requestback to summary
public void request(HttpMethod method, String requestURI, Handler<AsyncResult<HttpClientRequest>> handler)

Implements io.vertx.core.http.HttpClient.request.

Doc from io.vertx.core.http.HttpClient.request.

Create an HTTP request to send to the server at the default host and port. The handler is called when the request is ready to be sent.

Parameters
method:HttpMethod

the HTTP method

requestURI:String

the relative URI

handler:Handler<AsyncResult<HttpClientRequest>>

the handler called when the request is ready to be sent

Annotations
@Override
requestback to summary
public Future<HttpClientRequest> request(HttpMethod method, String requestURI)

Overrides default io.vertx.core.http.HttpClient.request.

Doc from io.vertx.core.http.HttpClient.request.

Like request(HttpMethod, String, Handler) but returns a Future of the asynchronous result

Annotations
@Override
io.vertx.core.http.impl back to summary

private Class HttpClientImpl.PoolChecker

extends Object
implements Handler<Long>
Class Inheritance
All Implemented Interfaces
io.vertx.core.Handler

A weak ref to the client so it can be finalized.

Field Summary

Modifier and TypeField and Description
pack-priv final WeakReference<HttpClientImpl>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
handle(Long
the event to handle
event
)

Implements io.vertx.core.Handler.handle.

Something has happened, so handle it.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

refback to summary
pack-priv final WeakReference<HttpClientImpl> ref

Constructor Detail

PoolCheckerback to summary
private PoolChecker(HttpClientImpl client)

Method Detail

handleback to summary
public void handle(Long event)

Implements io.vertx.core.Handler.handle.

Doc from io.vertx.core.Handler.handle.

Something has happened, so handle it.

Parameters
event:Long

the event to handle

Annotations
@Override