Interface Destination
- All Known Implementing Classes:
HttpDestination
A Destination represents the receiver of HTTP requests, and it is
identified by an Origin.
Destination holds a pool of Connections, but allows to create unpooled
connections if the application wants full control over connection management via
newConnection(Promise).
Destinations may be obtained via HttpClient.resolveDestination(Request).
-
Method Summary
Modifier and TypeMethodDescriptiongetProxy()booleanisSecure()default CompletableFuture<Connection> Creates asynchronously a new, unpooled,Connectionthat will be returned at a later time through the givenPromise.voidnewConnection(Promise<Connection> promise) Creates asynchronously a new, unpooled,Connectionthat will be returned at a later time through the givenPromise.voidsend(Request request, Response.CompleteListener listener) Sends the given request to this destination.
-
Method Details
-
getOrigin
Origin getOrigin()- Returns:
- the origin of this destination
-
isSecure
boolean isSecure()- Returns:
- whether the communication with the destination is secure
-
getProxy
ProxyConfiguration.Proxy getProxy()- Returns:
- the proxy associated with this destination,
or
nullif there is no proxy
-
getConnectionPool
ConnectionPool getConnectionPool()- Returns:
- the connection pool associated with this destination
-
getHttpClient
HttpClient getHttpClient()- Returns:
- the
HttpClientthat manages this destination
-
newConnection
Creates asynchronously a new, unpooled,Connectionthat will be returned at a later time through the givenPromise.Use
FuturePromiseto wait for the connection:Destination destination = ...; FuturePromise<Connection> futureConnection = new FuturePromise<>(); destination.newConnection(futureConnection); Connection connection = futureConnection.get(5, TimeUnit.SECONDS);- Parameters:
promise- the promise of a new, unpooled,Connection
-
newConnection
Creates asynchronously a new, unpooled,
Connectionthat will be returned at a later time through the givenPromise.- Returns:
- a
CompletableFuturefor a new, unpooled,Connection
-
send
Sends the given request to this destination.
You can use this method to send the request to a specific destination that may be different from the request authority.
For example when
HttpClientis used in a proxy, it may receive a request with authorityyourserver.combut the proxy logic may want to forward the request to a specific backend server, saybackend01, therefore:// Resolve the backend destination. Origin backendOrigin = new Origin(backendScheme, "backend01", backendPort); Destination backendDestination = httpClient.resolveDestination(backendOrigin); // Create a request with the original authority. Request request = httpClient.newRequest("https://yourserver.com/path"); // Send the request to the specific backend. backendDestination.send(request, result -> { ... });- Parameters:
request- the request to send to this destinationlistener- the listener that receives response events
-