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 Connection
s, but allows to create unpooled
connections if the application wants full control over connection management via
newConnection(Promise)
.
Destination
s may be obtained via HttpClient.resolveDestination(Request)
.
-
Method Summary
Modifier and TypeMethodDescriptiongetProxy()
boolean
isSecure()
default CompletableFuture<Connection>
Creates asynchronously a new, unpooled,Connection
that will be returned at a later time through the givenPromise
.void
newConnection
(Promise<Connection> promise) Creates asynchronously a new, unpooled,Connection
that will be returned at a later time through the givenPromise
.void
send
(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
null
if there is no proxy
-
getConnectionPool
ConnectionPool getConnectionPool()- Returns:
- the connection pool associated with this destination
-
getHttpClient
HttpClient getHttpClient()- Returns:
- the
HttpClient
that manages this destination
-
newConnection
Creates asynchronously a new, unpooled,Connection
that will be returned at a later time through the givenPromise
.Use
FuturePromise
to 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,
Connection
that will be returned at a later time through the givenPromise
.- Returns:
- a
CompletableFuture
for 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
HttpClient
is used in a proxy, it may receive a request with authorityyourserver.com
but 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
-