Class JavaNetSoTimeoutHttpConnectionFilter
- All Implemented Interfaces:
HttpExecutionStrategyInfluencer
,StreamingHttpConnectionFilterFactory
,ExecutionStrategyInfluencer<HttpExecutionStrategy>
SocketOptions.SO_TIMEOUT
behavior on the client-side.
While TimeoutHttpRequesterFilter
applies a timeout for the overall duration to receive either the response
metadata (headers) or the complete reception of the response (including headers, payload body, optional trailers, as
well as time to send the request), this filter applies timeout to every independent read operation: read of 100
(Continue) response, read of response headers, read of every response payload body chunk, read of optional trailers.
Note that the time to send the request is not accounted. Also, if the remote server is sending a large payload
body, the timeout will be applied on every chunk read, which may result in unpredictable time to read the full
response if the remote slowly sends 1 byte within the timeout boundaries. Use this filter only for compatibility with
classic blocking Java libraries. To protect from the described use-cases, consider also appending
TimeoutHttpRequesterFilter
before applying this filter in the filter chain.
This filter implements only StreamingHttpConnectionFilterFactory
and therefore can be applied only at the
connection level. This restriction ensures that the timeout is applied only for the response read operations
(similar to SocketOptions.SO_TIMEOUT
used by Java blocking API), without waiting for selecting or
establishing a connection.
SocketTimeoutException
(or its subtype) will be propagated when the timeout is reached.
-
Constructor Summary
ConstructorDescriptionJavaNetSoTimeoutHttpConnectionFilter
(Duration duration) Creates a new instance.JavaNetSoTimeoutHttpConnectionFilter
(Duration duration, Executor timeoutExecutor) Creates a new instance.JavaNetSoTimeoutHttpConnectionFilter
(BiFunction<HttpRequestMetaData, TimeSource, Duration> timeoutForRequest) Creates a new instance.JavaNetSoTimeoutHttpConnectionFilter
(BiFunction<HttpRequestMetaData, TimeSource, Duration> timeoutForRequest, Executor timeoutExecutor) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptioncreate
(FilterableStreamingHttpConnection connection) Create aStreamingHttpConnectionFilter
using the providedFilterableStreamingHttpConnection
.Return anExecutionStrategy
that describes the offloads required by the influencer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.servicetalk.http.api.HttpExecutionStrategyInfluencer
influenceStrategy
-
Constructor Details
-
JavaNetSoTimeoutHttpConnectionFilter
Creates a new instance.- Parameters:
duration
- the timeoutDuration
, must be> 0
-
JavaNetSoTimeoutHttpConnectionFilter
Creates a new instance. -
JavaNetSoTimeoutHttpConnectionFilter
public JavaNetSoTimeoutHttpConnectionFilter(BiFunction<HttpRequestMetaData, TimeSource, Duration> timeoutForRequest) Creates a new instance.- Parameters:
timeoutForRequest
- function for extracting timeout value from a request or other runtime sources. A timeout ofnull
orzero (0)
is interpreted as an infinite timeout, all other values must be> 0
-
JavaNetSoTimeoutHttpConnectionFilter
public JavaNetSoTimeoutHttpConnectionFilter(BiFunction<HttpRequestMetaData, TimeSource, Duration> timeoutForRequest, Executor timeoutExecutor) Creates a new instance.
-
-
Method Details
-
create
Description copied from interface:StreamingHttpConnectionFilterFactory
Create aStreamingHttpConnectionFilter
using the providedFilterableStreamingHttpConnection
.- Specified by:
create
in interfaceStreamingHttpConnectionFilterFactory
- Parameters:
connection
-FilterableStreamingHttpConnection
to filter- Returns:
StreamingHttpConnectionFilter
using the providedFilterableStreamingHttpConnection
.
-
requiredOffloads
Description copied from interface:HttpExecutionStrategyInfluencer
Return anExecutionStrategy
that describes the offloads required by the influencer.The provided default implementation requests offloading of all operations. Implementations that require no offloading should be careful to return
HttpExecutionStrategies.offloadNone()
rather thanHttpExecutionStrategies.offloadNever()
. Implementations should avoid returningHttpExecutionStrategies.defaultStrategy()
, instead returning the strategy they require orHttpExecutionStrategies.offloadAll()
if offloading for all paths is required (safe default).- Specified by:
requiredOffloads
in interfaceExecutionStrategyInfluencer<HttpExecutionStrategy>
- Specified by:
requiredOffloads
in interfaceHttpExecutionStrategyInfluencer
- Returns:
- the
ExecutionStrategy
required by the influencer.
-