Interface SingleAddressHttpClientBuilder<U,R>
- Type Parameters:
U
- the type of address before resolution (unresolved address)R
- the type of address after resolution (resolved address)
- All Known Implementing Classes:
DefaultHttpLoadBalancerProvider.LoadBalancerIgnoringBuilder
,DelegatingSingleAddressHttpClientBuilder
StreamingHttpClient
instances which call a single server based on the provided unresolved
address.
It also provides a good set of default settings and configurations, which could be used by most users as-is or could be overridden to address specific use cases.
-
Method Summary
Modifier and TypeMethodDescriptionallowDropResponseTrailers
(boolean allowDrop) Provide a hint if response trailers are allowed to be dropped.Appends the filter to the chain of filters used to decorate theHttpClient
created by this builder.appendClientFilter
(Predicate<StreamingHttpRequest> predicate, StreamingHttpClientFilterFactory factory) Appends the filter to the chain of filters used to decorate theHttpClient
created by this builder, for every request that passes the providedPredicate
.Appends the filter to the chain of filters used to decorate theConnectionFactory
used by this builder.Appends the filter to the chain of filters used to decorate theStreamingHttpConnection
created by this builder.appendConnectionFilter
(Predicate<StreamingHttpRequest> predicate, StreamingHttpConnectionFilterFactory factory) Appends the filter to the chain of filters used to decorate theStreamingHttpConnection
created by this builder, for every request that passes the providedPredicate
.bufferAllocator
(BufferAllocator allocator) default HttpClient
build()
Builds a newHttpClient
.default BlockingHttpClient
Creates a newBlockingHttpClient
.default BlockingStreamingHttpClient
Creates a newBlockingStreamingHttpClient
.Builds a newStreamingHttpClient
.enableWireLogging
(String loggerName, LogLevel logLevel, BooleanSupplier logUserData) Enables wire-logging for connections created by this builder.executionStrategy
(HttpExecutionStrategy strategy) Sets theHttpExecutionStrategy
to be used for client callbacks when executing client requests for all clients created from this builder.hostHeaderFallback
(boolean enable) Configures automatically settingHost
headers by inferring from the address.inferPeerHost
(boolean shouldInfer) Toggle inference of value to use instead ofClientSslConfig.peerHost()
from client's address when peer host is not specified.inferPeerPort
(boolean shouldInfer) Toggle inference of value to use instead ofClientSslConfig.peerPort()
from client's address when peer port is not specified (equals-1
).inferSniHostname
(boolean shouldInfer) Toggle SNI hostname inference from client's address if not explicitly specified viasslConfig(ClientSslConfig)
.ioExecutor
(IoExecutor ioExecutor) loadBalancerFactory
(HttpLoadBalancerFactory<R> loadBalancerFactory) Sets aHttpLoadBalancerFactory
to createLoadBalancer
instances.protocols
(HttpProtocolConfig... protocols) Configurations of various HTTP protocol versions.default SingleAddressHttpClientBuilder<U,
R> proxyAddress
(U proxyAddress) Deprecated.default SingleAddressHttpClientBuilder<U,
R> proxyConfig
(ProxyConfig<U> proxyConfig) Configures a proxy to serve as an intermediary for requests.retryServiceDiscoveryErrors
(BiIntFunction<Throwable, ? extends Completable> retryStrategy) Sets a retry strategy to retry errors emitted byServiceDiscoverer
.serviceDiscoverer
(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer) Sets aServiceDiscoverer
to resolve addresses of remote servers to connect to.socketOption
(SocketOption<T> option, T value) Adds aSocketOption
for all connections created by this builder.sslConfig
(ClientSslConfig sslConfig) Set the SSL/TLS configuration.default SingleAddressHttpClientBuilder<U,
R> transportConfig
(TransportConfig transportConfig) Set the transport configuration.unresolvedAddressToHost
(Function<U, CharSequence> unresolvedAddressToHostFunction) Provides a means to convertSingleAddressHttpClientBuilder
unresolved address type into aCharSequence
.
-
Method Details
-
proxyAddress
Deprecated.Configures a proxy to serve as an intermediary for requests.If the client talks to a proxy over http (not https,
ClientSslConfig
is NOT configured), it will rewrite the request-target to absolute-form, as specified by the RFC.For secure proxy tunnels (when
ClientSslConfig
is configured) the tunnel is always initialized using HTTP/1.1 CONNECT request. The actual protocol will be negotiated via ALPN extension of TLS protocol, taking into account HTTP protocols configured viaprotocols(HttpProtocolConfig...)
method. In case of any error duringCONNECT
process,ProxyConnectException
orProxyConnectResponseException
will be thrown when a request attempt is made through the constructed client instance.- Parameters:
proxyAddress
- Unresolved address of the proxy. When used with a builder created for a resolved address,proxyAddress
should also be already resolved – otherwise runtime exceptions may occur.- Returns:
this
.
-
proxyConfig
Configures a proxy to serve as an intermediary for requests.If the client talks to a proxy over http (not https,
ClientSslConfig
is NOT configured), it will rewrite the request-target to absolute-form, as specified by the RFC.For secure proxy tunnels (when
ClientSslConfig
is configured) the tunnel is always initialized using HTTP/1.1 CONNECT request. The actual protocol will be negotiated via ALPN extension of TLS protocol, taking into account HTTP protocols configured viaprotocols(HttpProtocolConfig...)
method. In case of any error duringCONNECT
process,ProxyConnectException
orProxyConnectResponseException
will be thrown when a request attempt is made through the constructed client instance.- Parameters:
proxyConfig
- Configuration for a proxy. When used with a builder created for a resolved address,ProxyConfig.address()
must also be already resolved – otherwise runtime exceptions will occur.- Returns:
this
.- See Also:
-
socketOption
Adds aSocketOption
for all connections created by this builder.- Type Parameters:
T
- the type of the value.- Parameters:
option
- the option to apply.value
- the value.- Returns:
this
.- See Also:
-
enableWireLogging
SingleAddressHttpClientBuilder<U,R> enableWireLogging(String loggerName, LogLevel logLevel, BooleanSupplier logUserData) Enables wire-logging for connections created by this builder.- Parameters:
loggerName
- The name of the logger to log wire events.logLevel
- The level to log at.logUserData
-true
to include user data (e.g. data, headers, etc.).false
to exclude user data and log only network events. This method is invoked for each data object allowing for dynamic behavior.- Returns:
this
.
-
protocols
Configurations of various HTTP protocol versions.Note: the order of specified protocols will reflect on priorities for ALPN in case the connections use TLS.
- Parameters:
protocols
-HttpProtocolConfig
for each protocol that should be supported.- Returns:
this
.
-
hostHeaderFallback
Configures automatically settingHost
headers by inferring from the address.When
false
is passed, this setting disables the default filter such that noHost
header will be manipulated.- Parameters:
enable
- Whether a default filter for inferring theHost
headers should be added.- Returns:
this
- See Also:
-
allowDropResponseTrailers
Provide a hint if response trailers are allowed to be dropped. This hint maybe ignored if the transport can otherwise infer that trailers should be preserved. For example, if the response headers contain Trailer then this hint maybe ignored.- Parameters:
allowDrop
-true
if response trailers are allowed to be dropped.- Returns:
this
-
appendConnectionFilter
SingleAddressHttpClientBuilder<U,R> appendConnectionFilter(StreamingHttpConnectionFilterFactory factory) Appends the filter to the chain of filters used to decorate theStreamingHttpConnection
created by this builder.Filtering allows you to wrap a
StreamingHttpConnection
and modify behavior during request/response processing Some potential candidates for filtering include logging, metrics, and decorating responses.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.appendConnectionFilter(filter1).appendConnectionFilter(filter2).appendConnectionFilter(filter3)
making a request to a connection wrapped by this filter chain the order of invocation of these filters will be:filter1 ⇒ filter2 ⇒ filter3 ⇒ connection
- Parameters:
factory
-StreamingHttpConnectionFilterFactory
to decorate aStreamingHttpConnection
for the purpose of filtering.- Returns:
this
-
appendConnectionFilter
SingleAddressHttpClientBuilder<U,R> appendConnectionFilter(Predicate<StreamingHttpRequest> predicate, StreamingHttpConnectionFilterFactory factory) Appends the filter to the chain of filters used to decorate theStreamingHttpConnection
created by this builder, for every request that passes the providedPredicate
.Filtering allows you to wrap a
StreamingHttpConnection
and modify behavior during request/response processing Some potential candidates for filtering include logging, metrics, and decorating responses.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.appendConnectionFilter(filter1).appendConnectionFilter(filter2).appendConnectionFilter(filter3)
making a request to a connection wrapped by this filter chain the order of invocation of these filters will be:filter1 ⇒ filter2 ⇒ filter3 ⇒ connection
When overriding this method, delegate to
super
as it uses internal utilities to provide a consistent execution flow.- Parameters:
predicate
- thePredicate
to test if the filter must be applied.factory
-StreamingHttpConnectionFilterFactory
to decorate aStreamingHttpConnection
for the purpose of filtering.- Returns:
this
-
ioExecutor
-
executor
-
executionStrategy
Sets theHttpExecutionStrategy
to be used for client callbacks when executing client requests for all clients created from this builder.Specifying an execution strategy affects the offloading used during execution of client requests:
- Unspecified or
HttpExecutionStrategies.defaultStrategy()
- Execution of client requests will use a safe (non-blocking) execution strategy appropriate for the
client API used and the filters added. Blocking is always safe as all potentially blocking paths are
offloaded. Each client API variant (async/blocking streaming/aggregate) requires a specific execution
strategy to avoid blocking the event-loop and filters added via
appendClientFilter(StreamingHttpClientFilterFactory)
,appendConnectionFilter(StreamingHttpConnectionFilterFactory)
, orappendConnectionFactoryFilter(ConnectionFactoryFilter)
, etc. may also require offloading. The execution strategy for execution of client requests will be computed based on the client API in use andHttpExecutionStrategyInfluencer.requiredOffloads()
of added the filters. HttpExecutionStrategies.offloadNone()
(or deprecatedHttpExecutionStrategies.offloadNever()
)- No offloading will be used during execution of client requests regardless of the client API used or the influence of added filters. Filters and asynchronous callbacks must not ever block during the execution of client requests.
- A custom execution strategy (
HttpExecutionStrategies.customStrategyBuilder()
) orHttpExecutionStrategies.offloadAll()
- The specified execution strategy will be used for executing client requests rather than the client API's default safe strategy. Like with the default strategy, the actual execution strategy used is computed from the provided strategy and the execution strategies required by added filters. Filters and asynchronous callbacks MAY only block during the offloaded portions of the client request execution.
- Parameters:
strategy
-HttpExecutionStrategy
to use. If callbacks to the application code may block then those callbacks must request to be offloaded.- Returns:
this
.- See Also:
- Unspecified or
-
bufferAllocator
-
appendConnectionFactoryFilter
SingleAddressHttpClientBuilder<U,R> appendConnectionFactoryFilter(ConnectionFactoryFilter<R, FilterableStreamingHttpConnection> factory) Appends the filter to the chain of filters used to decorate theConnectionFactory
used by this builder.Filtering allows you to wrap a
ConnectionFactory
and modify behavior ofConnectionFactory.newConnection(Object, ContextMap, TransportObserver)
. Some potential candidates for filtering include logging and metrics.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder .appendConnectionFactoryFilter(filter1) .appendConnectionFactoryFilter(filter2) .appendConnectionFactoryFilter(filter3)
CallingConnectionFactory
wrapped by this filter chain, the order of invocation of these filters will be:filter1 ⇒ filter2 ⇒ filter3 ⇒ original connection factory
- Parameters:
factory
-ConnectionFactoryFilter
to use.- Returns:
this
-
appendClientFilter
Appends the filter to the chain of filters used to decorate theHttpClient
created by this builder.Note this method will be used to decorate the result of
build()
before it is returned to the user.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.appendClientFilter(filter1).appendClientFilter(filter2).appendClientFilter(filter3)
making a request to a client wrapped by this filter chain the order of invocation of these filters will be:filter1 ⇒ filter2 ⇒ filter3 ⇒ client
- Parameters:
factory
-StreamingHttpClientFilterFactory
to decorate aHttpClient
for the purpose of filtering.- Returns:
this
-
appendClientFilter
SingleAddressHttpClientBuilder<U,R> appendClientFilter(Predicate<StreamingHttpRequest> predicate, StreamingHttpClientFilterFactory factory) Appends the filter to the chain of filters used to decorate theHttpClient
created by this builder, for every request that passes the providedPredicate
.Note this method will be used to decorate the result of
build()
before it is returned to the user.The order of execution of these filters are in order of append. If 3 filters are added as follows:
builder.appendClientFilter(filter1).appendClientFilter(filter2).appendClientFilter(filter3)
making a request to a client wrapped by this filter chain the order of invocation of these filters will be:filter1 ⇒ filter2 ⇒ filter3 ⇒ client
- Parameters:
predicate
- thePredicate
to test if the filter must be applied.factory
-StreamingHttpClientFilterFactory
to decorate aHttpClient
for the purpose of filtering.- Returns:
this
-
unresolvedAddressToHost
SingleAddressHttpClientBuilder<U,R> unresolvedAddressToHost(Function<U, CharSequence> unresolvedAddressToHostFunction) Provides a means to convertSingleAddressHttpClientBuilder
unresolved address type into aCharSequence
. An example of where this maybe used is to convert theSingleAddressHttpClientBuilder
to a default host header. It may also be used in the event of proxying.- Parameters:
unresolvedAddressToHostFunction
- invoked to convert theSingleAddressHttpClientBuilder
unresolved address type into aCharSequence
suitable for use in Host Header format.- Returns:
this
-
serviceDiscoverer
SingleAddressHttpClientBuilder<U,R> serviceDiscoverer(ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> serviceDiscoverer) Sets aServiceDiscoverer
to resolve addresses of remote servers to connect to.- Parameters:
serviceDiscoverer
- TheServiceDiscoverer
to resolve addresses of remote servers to connect to. Lifecycle of the providedServiceDiscoverer
is managed externally and it should beclosed
after all builtStreamingHttpClient
s will be closed and thisServiceDiscoverer
is no longer needed.- Returns:
this
.
-
retryServiceDiscoveryErrors
SingleAddressHttpClientBuilder<U,R> retryServiceDiscoveryErrors(BiIntFunction<Throwable, ? extends Completable> retryStrategy) Sets a retry strategy to retry errors emitted byServiceDiscoverer
.- Parameters:
retryStrategy
- a retry strategy to retry errors emitted byServiceDiscoverer
.- Returns:
this
.- See Also:
-
loadBalancerFactory
SingleAddressHttpClientBuilder<U,R> loadBalancerFactory(HttpLoadBalancerFactory<R> loadBalancerFactory) Sets aHttpLoadBalancerFactory
to createLoadBalancer
instances.- Parameters:
loadBalancerFactory
-HttpLoadBalancerFactory
to createLoadBalancer
instances.- Returns:
this
.
-
sslConfig
Set the SSL/TLS configuration.- Parameters:
sslConfig
- The configuration to use.- Returns:
this
.- See Also:
-
inferPeerHost
Toggle inference of value to use instead ofClientSslConfig.peerHost()
from client's address when peer host is not specified. By default, inference is enabled.- Parameters:
shouldInfer
- value indicating whether inference is on (true
) or off (false
).- Returns:
this
-
inferPeerPort
Toggle inference of value to use instead ofClientSslConfig.peerPort()
from client's address when peer port is not specified (equals-1
). By default, inference is enabled.- Parameters:
shouldInfer
- value indicating whether inference is on (true
) or off (false
).- Returns:
this
-
inferSniHostname
Toggle SNI hostname inference from client's address if not explicitly specified viasslConfig(ClientSslConfig)
. By default, inference is enabled.- Parameters:
shouldInfer
- value indicating whether inference is on (true
) or off (false
).- Returns:
this
-
transportConfig
Set the transport configuration.- Parameters:
transportConfig
-TransportConfig
to use- Returns:
this
- See Also:
-
buildStreaming
StreamingHttpClient buildStreaming()Builds a newStreamingHttpClient
.- Returns:
- A new
StreamingHttpClient
- Throws:
IllegalArgumentException
- for incomplete or illegal configurationsIllegalStateException
- for unsupported configuration combinations
-
build
Builds a newHttpClient
.- Returns:
- A new
HttpClient
-
buildBlockingStreaming
Creates a newBlockingStreamingHttpClient
.- Returns:
BlockingStreamingHttpClient
-
buildBlocking
Creates a newBlockingHttpClient
.- Returns:
BlockingHttpClient
-
proxyConfig(ProxyConfig)
withProxyConfig.forAddress(Object)
.