Package com.linecorp.armeria.client
Interface ClientRequestContext
- All Superinterfaces:
RequestContext
- All Known Implementing Classes:
ClientRequestContextWrapper
,DefaultClientRequestContext
public interface ClientRequestContext extends RequestContext
Provides information about a
Request
, its Response
and its related utilities.
Every client request has its own ClientRequestContext
instance.-
Method Summary
Modifier and Type Method Description void
addAdditionalRequestHeader(CharSequence name, Object value)
Adds a header with the specifiedname
andvalue
.HttpHeaders
additionalRequestHeaders()
<V> V
attr(AttributeKey<V> key)
Returns the value mapped to the givenAttributeKey
ornull
if there's no value set byRequestContext.setAttr(AttributeKey, Object)
orRequestContext.setAttrIfAbsent(AttributeKey, Object)
.Iterator<Map.Entry<AttributeKey<?>,Object>>
attrs()
static ClientRequestContextBuilder
builder(HttpRequest request)
Returns a newClientRequestContextBuilder
created from the specifiedHttpRequest
.static ClientRequestContextBuilder
builder(RpcRequest request, String uri)
static ClientRequestContextBuilder
builder(RpcRequest request, URI uri)
void
clearResponseTimeout()
Clears the previously scheduled response timeout, if any.static ClientRequestContext
current()
Returns the client-side context of theRequest
that is being handled in the current thread.static ClientRequestContext
currentOrNull()
Returns the client-side context of theRequest
that is being handled in the current thread.Endpoint
endpoint()
EndpointGroup
endpointGroup()
Returns theEndpointGroup
used for the currentRequest
.default void
extendResponseTimeout(Duration adjustment)
Deprecated.default void
extendResponseTimeoutMillis(long adjustmentMillis)
Deprecated.String
fragment()
Returns the fragment part of the URI of the currentRequest
, as defined in the section 3.5 of RFC3986.static <T> T
mapCurrent(Function<? super ClientRequestContext,T> mapper, Supplier<T> defaultValueSupplier)
Maps the client-side context of theRequest
that is being handled in the current thread.long
maxResponseLength()
Returns the maximum length of the receivedResponse
.void
mutateAdditionalRequestHeaders(Consumer<HttpHeadersBuilder> mutator)
default ClientRequestContext
newDerivedContext(RequestId id, HttpRequest req, RpcRequest rpcReq)
Creates a newClientRequestContext
whose properties andAttribute
s are copied from thisClientRequestContext
, except having a differentRequest
and its ownRequestLog
.ClientRequestContext
newDerivedContext(RequestId id, HttpRequest req, RpcRequest rpcReq, Endpoint endpoint)
Creates a newClientRequestContext
whose properties andAttribute
s are copied from thisClientRequestContext
, except having differentRequest
,Endpoint
and its ownRequestLog
.static ClientRequestContext
of(HttpRequest request)
Returns a newClientRequestContext
created from the specifiedHttpRequest
.static ClientRequestContext
of(RpcRequest request, String uri)
Returns a newClientRequestContext
created from the specifiedRpcRequest
and URI.static ClientRequestContext
of(RpcRequest request, URI uri)
ClientOptions
options()
Returns theClientOptions
of the currentRequest
.<V> V
ownAttr(AttributeKey<V> key)
Returns the value mapped to the givenAttributeKey
ornull
if there's no value set byRequestContext.setAttr(AttributeKey, Object)
orRequestContext.setAttrIfAbsent(AttributeKey, Object)
.Iterator<Map.Entry<AttributeKey<?>,Object>>
ownAttrs()
default SafeCloseable
push()
Pushes this context to the thread-local stack.HttpRequest
request()
Returns theHttpRequest
associated with this context, ornull
if there's noHttpRequest
associated with this context yet.Runnable
responseTimeoutHandler()
ReturnsResponse
timeout handler which is executed when theResponse
is not completely received within the allowedresponseTimeoutMillis()
or the defaultClientOption.RESPONSE_TIMEOUT_MILLIS
.long
responseTimeoutMillis()
ServiceRequestContext
root()
Returns theServiceRequestContext
whoseService
invokes theClient
Request
which created thisClientRequestContext
, ornull
if this client request was not made in the context of a server request.RpcRequest
rpcRequest()
Returns theRpcRequest
associated with this context, ornull
if there's noRpcRequest
associated with this context.void
setAdditionalRequestHeader(CharSequence name, Object value)
Sets a header with the specifiedname
andvalue
.void
setMaxResponseLength(long maxResponseLength)
Sets the maximum length of the receivedResponse
.default void
setResponseTimeout(TimeoutMode mode, Duration responseTimeout)
Schedules the response timeout that is triggered when theResponse
is not fully received within the specifiedTimeoutMode
and the specifiedresponseTimeoutMillis
since theResponse
started orRequest
was fully sent.default void
setResponseTimeout(Duration responseTimeout)
Schedules the response timeout that is triggered when theResponse
is not fully received within the specified amount of time from now.default void
setResponseTimeoutAfter(Duration responseTimeout)
Deprecated.default void
setResponseTimeoutAfterMillis(long responseTimeoutMillis)
Deprecated.default void
setResponseTimeoutAt(Instant responseTimeoutAt)
Deprecated.This method will be removed without a replacement.void
setResponseTimeoutAtMillis(long responseTimeoutAtMillis)
Deprecated.This method will be removed without a replacement.void
setResponseTimeoutHandler(Runnable responseTimeoutHandler)
Sets a handler to run when the response times out.default void
setResponseTimeoutMillis(long responseTimeoutMillis)
Schedules the response timeout that is triggered when theResponse
is not fully received within the specified amount of time from now.void
setResponseTimeoutMillis(TimeoutMode mode, long responseTimeoutMillis)
Schedules the response timeout that is triggered when theResponse
is not fully received within the specifiedTimeoutMode
and the specifiedresponseTimeoutMillis
since theResponse
started orRequest
was fully sent.void
setWriteTimeout(Duration writeTimeout)
Returns the amount of time allowed until the initial write attempt of the currentRequest
succeeds.void
setWriteTimeoutMillis(long writeTimeoutMillis)
Returns the amount of time allowed until the initial write attempt of the currentRequest
succeeds.long
writeTimeoutMillis()
Returns the amount of time allowed until the initial write attempt of the currentRequest
succeeds.Methods inherited from interface com.linecorp.armeria.common.RequestContext
alloc, computeAttrIfAbsent, contextAwareEventLoop, contextAwareExecutor, decodedPath, eventLoop, executor, id, localAddress, log, logBuilder, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, meterRegistry, method, path, query, remoteAddress, replace, sessionProtocol, setAttr, setAttrIfAbsent, sslSession, updateRequest, updateRpcRequest
-
Method Details
-
current
Returns the client-side context of theRequest
that is being handled in the current thread.- Throws:
IllegalStateException
- if the context is unavailable in the current thread or the current context is not aClientRequestContext
.
-
currentOrNull
Returns the client-side context of theRequest
that is being handled in the current thread.- Returns:
- the
ClientRequestContext
available in the current thread, ornull
if unavailable. - Throws:
IllegalStateException
- if the current context is not aClientRequestContext
.
-
mapCurrent
@Nullable static <T> T mapCurrent(Function<? super ClientRequestContext,T> mapper, @Nullable Supplier<T> defaultValueSupplier)Maps the client-side context of theRequest
that is being handled in the current thread.- Parameters:
mapper
- theFunction
that maps theClientRequestContext
defaultValueSupplier
- theSupplier
that provides the value when the context is unavailable in the current thread. Ifnull
, thenull
will be returned when the context is unavailable in the current thread.- Throws:
IllegalStateException
- if the current context is not aClientRequestContext
.
-
of
Returns a newClientRequestContext
created from the specifiedHttpRequest
. Note that it is not usually required to create a new context by yourself, because Armeria will always provide a context object for you. However, it may be useful in some cases such as unit testing.- See Also:
ClientRequestContextBuilder
-
of
Returns a newClientRequestContext
created from the specifiedRpcRequest
and URI. Note that it is not usually required to create a new context by yourself, because Armeria will always provide a context object for you. However, it may be useful in some cases such as unit testing.- See Also:
ClientRequestContextBuilder
-
of
Returns a newClientRequestContext
created from the specifiedRpcRequest
andURI
. Note that it is not usually required to create a new context by yourself, because Armeria will always provide a context object for you. However, it may be useful in some cases such as unit testing.- See Also:
ClientRequestContextBuilder
-
builder
Returns a newClientRequestContextBuilder
created from the specifiedHttpRequest
. -
builder
-
builder
-
root
Returns theServiceRequestContext
whoseService
invokes theClient
Request
which created thisClientRequestContext
, ornull
if this client request was not made in the context of a server request. -
attr
Returns the value mapped to the givenAttributeKey
ornull
if there's no value set byRequestContext.setAttr(AttributeKey, Object)
orRequestContext.setAttrIfAbsent(AttributeKey, Object)
.If the value does not exist in this context but only in
root()
, this method will return the value from theroot()
.
If the value exists both in this context andClientRequestContext ctx = ...; assert ctx.root().attr(KEY).equals("root"); assert ctx.attr(KEY).equals("root"); assert ctx.ownAttr(KEY) == null;
root()
, this method will return the value from this context.ClientRequestContext ctx = ...; assert ctx.root().attr(KEY).equals("root"); assert ctx.ownAttr(KEY).equals("child"); assert ctx.attr(KEY).equals("child");
- Specified by:
attr
in interfaceRequestContext
- See Also:
ownAttr(AttributeKey)
-
ownAttr
Returns the value mapped to the givenAttributeKey
ornull
if there's no value set byRequestContext.setAttr(AttributeKey, Object)
orRequestContext.setAttrIfAbsent(AttributeKey, Object)
. Unlikeattr(AttributeKey)
, this does not search inroot()
.- See Also:
attr(AttributeKey)
-
attrs
Iterator<Map.Entry<AttributeKey<?>,Object>> attrs()Returns theIterator
of allMap.Entry
s this context contains.The
Iterator
returned by this method will also yield theMap.Entry
s from theroot()
except those whoseAttributeKey
exist already in this context, e.g.
Please note that any changes made to theClientRequestContext ctx = ...; assert ctx.ownAttr(KEY_A).equals("child_a"); assert ctx.root().attr(KEY_A).equals("root_a"); assert ctx.root().attr(KEY_B).equals("root_b"); Iterator<Entry<AttributeKey<?>, Object>> attrs = ctx.attrs(); assert attrs.next().getValue().equals("child_a"); // KEY_A // Skip KEY_A in the root. assert attrs.next().getValue().equals("root_b"); // KEY_B assert attrs.hasNext() == false;
Map.Entry
returned byIterator.next()
never affects theMap.Entry
owned byroot()
. For example:
If you want to change the value from the root while iterating, please callClientRequestContext ctx = ...; assert ctx.root().attr(KEY).equals("root"); assert ctx.ownAttr(KEY) == null; Iterator<Entry<AttributeKey<?>, Object>> attrs = ctx.attrs(); Entry<AttributeKey<?>, Object> next = attrs.next(); assert next.getKey() == KEY; // Overriding the root entry creates the client context's own entry. next.setValue("child"); assert ctx.attr(KEY).equals("child"); assert ctx.ownAttr(KEY).equals("child"); // root attribute remains unaffected. assert ctx.root().attr(KEY).equals("root");
attrs()
fromroot()
.ClientRequestContext ctx = ...; assert ctx.root().attr(KEY).equals("root"); assert ctx.ownAttr(KEY) == null; // Call attrs() from the root to set a value directly while iterating. Iterator<Entry<AttributeKey<?>, Object>> attrs = ctx.root().attrs(); Entry<AttributeKey<?>, Object> next = attrs.next(); assert next.getKey() == KEY; next.setValue("another_root"); // The ctx does not have its own attribute. assert ctx.ownAttr(KEY) == null; assert ctx.attr(KEY).equals("another_root");
- Specified by:
attrs
in interfaceRequestContext
- See Also:
ownAttrs()
-
ownAttrs
Iterator<Map.Entry<AttributeKey<?>,Object>> ownAttrs()Returns theIterator
of allMap.Entry
s this context contains. Unlikeattrs()
, this does not iterateroot()
.- See Also:
attrs()
-
request
Returns theHttpRequest
associated with this context, ornull
if there's noHttpRequest
associated with this context yet. For example, when you send an RPC request, this method will returnnull
until the RPC request is translated into an HTTP request.- Specified by:
request
in interfaceRequestContext
-
rpcRequest
Returns theRpcRequest
associated with this context, ornull
if there's noRpcRequest
associated with this context. For example, this method will returnnull
when you are not sending an RPC request but just a plain HTTP request.- Specified by:
rpcRequest
in interfaceRequestContext
-
push
Pushes this context to the thread-local stack. To pop the context from the stack, callSafeCloseable.close()
, which can be done using atry-with-resources
block:try (SafeCloseable ignored = ctx.push()) { ... }
In order to call this method, the current thread-local state must meet one of the following conditions:
- the thread-local does not have any
RequestContext
in it - the thread-local has the same
ClientRequestContext
as this - reentrance - the thread-local has the
ServiceRequestContext
which is the same asroot()
- the thread-local has the
ClientRequestContext
whoseroot()
is the sameroot()
- the thread-local has the
ClientRequestContext
whoseroot()
isnull
and thisroot()
isnull
IllegalStateException
.- Specified by:
push
in interfaceRequestContext
- the thread-local does not have any
-
newDerivedContext
default ClientRequestContext newDerivedContext(RequestId id, @Nullable HttpRequest req, @Nullable RpcRequest rpcReq)Creates a newClientRequestContext
whose properties andAttribute
s are copied from thisClientRequestContext
, except having a differentRequest
and its ownRequestLog
.Note that this method does not copy the
RequestLog
properties to the derived context.- Specified by:
newDerivedContext
in interfaceRequestContext
-
newDerivedContext
ClientRequestContext newDerivedContext(RequestId id, @Nullable HttpRequest req, @Nullable RpcRequest rpcReq, Endpoint endpoint)Creates a newClientRequestContext
whose properties andAttribute
s are copied from thisClientRequestContext
, except having differentRequest
,Endpoint
and its ownRequestLog
.Note that this method does not copy the
RequestLog
properties to the derived context. -
endpointGroup
Returns theEndpointGroup
used for the currentRequest
.- Returns:
- the
EndpointGroup
if a user specified anEndpointGroup
when initiating aRequest
.null
if a user specified anEndpoint
.
-
endpoint
-
options
ClientOptions options()Returns theClientOptions
of the currentRequest
. -
fragment
Returns the fragment part of the URI of the currentRequest
, as defined in the section 3.5 of RFC3986.- Returns:
- the fragment part of the request URI, or
null
if no fragment was specified
-
writeTimeoutMillis
long writeTimeoutMillis()Returns the amount of time allowed until the initial write attempt of the currentRequest
succeeds. This value is initially set fromClientOption.WRITE_TIMEOUT_MILLIS
. -
setWriteTimeoutMillis
void setWriteTimeoutMillis(long writeTimeoutMillis)Returns the amount of time allowed until the initial write attempt of the currentRequest
succeeds. This value is initially set fromClientOption.WRITE_TIMEOUT_MILLIS
. -
setWriteTimeout
Returns the amount of time allowed until the initial write attempt of the currentRequest
succeeds. This value is initially set fromClientOption.WRITE_TIMEOUT_MILLIS
. -
responseTimeoutMillis
long responseTimeoutMillis()Returns the amount of time allowed until receiving theResponse
completely since the transfer of theResponse
started. This value is initially set fromClientOption.RESPONSE_TIMEOUT_MILLIS
. -
clearResponseTimeout
void clearResponseTimeout()Clears the previously scheduled response timeout, if any. Note that calling this will prevent the response from ever being timed out. -
setResponseTimeoutMillis
Schedules the response timeout that is triggered when theResponse
is not fully received within the specifiedTimeoutMode
and the specifiedresponseTimeoutMillis
since theResponse
started orRequest
was fully sent. This value is initially set fromClientOption.RESPONSE_TIMEOUT_MILLIS
.Timeout mode description TimeoutMode.SET_FROM_NOW
Sets a given amount of timeout from the current time. TimeoutMode.SET_FROM_START
Sets a given amount of timeout since the current Response
began processing.TimeoutMode.EXTEND
Extends the previously scheduled timeout by the given amount of timeout. For example:
ClientRequestContext ctx = ...; // Schedules a timeout from the start time of the response ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_START, 2000); assert ctx.responseTimeoutMillis() == 2000; ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_START, 1000); assert ctx.responseTimeoutMillis() == 1000; // Schedules timeout after 3 seconds from now. ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_NOW, 3000); // Extends the previously scheduled timeout. long oldResponseTimeoutMillis = ctx.responseTimeoutMillis(); ctx.setResponseTimeoutMillis(TimeoutMode.EXTEND, 1000); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 1000; ctx.extendResponseTimeoutMillis(TimeoutMode.EXTEND, -500); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 500;
-
setResponseTimeoutMillis
default void setResponseTimeoutMillis(long responseTimeoutMillis)Schedules the response timeout that is triggered when theResponse
is not fully received within the specified amount of time from now. Note that the specifiedresponseTimeoutMillis
must be positive. This value is initially set fromClientOption.RESPONSE_TIMEOUT_MILLIS
. This method is a shortcut forsetResponseTimeoutMillis(TimeoutMode.SET_FROM_NOW, responseTimeoutMillis)
.For example:
ClientRequestContext ctx = ...; // Schedules timeout after 1 seconds from now. ctx.setResponseTimeoutMillis(1000);
- Parameters:
responseTimeoutMillis
- the amount of time allowed in milliseconds from now
-
setResponseTimeout
Schedules the response timeout that is triggered when theResponse
is not fully received within the specifiedTimeoutMode
and the specifiedresponseTimeoutMillis
since theResponse
started orRequest
was fully sent. This value is initially set fromClientOption.RESPONSE_TIMEOUT_MILLIS
.Timeout mode description TimeoutMode.SET_FROM_NOW
Sets a given amount of timeout from the current time. TimeoutMode.SET_FROM_START
Sets a given amount of timeout since the current Response
began processing.TimeoutMode.EXTEND
Extends the previously scheduled timeout by the given amount of timeout. For example:
ClientRequestContext ctx = ...; // Schedules a timeout from the start time of the response ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_START, Duration.ofSeconds(2)); assert ctx.responseTimeoutMillis() == 2000; ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_START, Duration.ofSeconds(1)); assert ctx.responseTimeoutMillis() == 1000; // Schedules timeout after 3 seconds from now. ctx.setResponseTimeoutMillis(TimeoutMode.SET_FROM_NOW, Duration.ofSeconds(3)); // Extends the previously scheduled timeout. long oldResponseTimeoutMillis = ctx.responseTimeoutMillis(); ctx.setResponseTimeoutMillis(TimeoutMode.EXTEND, Duration.ofSeconds(1)); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 1000; ctx.setResponseTimeoutMillis(TimeoutMode.EXTEND, Duration.ofMillis(-500)); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 500;
-
setResponseTimeout
Schedules the response timeout that is triggered when theResponse
is not fully received within the specified amount of time from now. Note that the specifiedresponseTimeout
must be positive. This value is initially set fromClientOption.RESPONSE_TIMEOUT_MILLIS
. This method is a shortcut forsetResponseTimeout(TimeoutMode.SET_FROM_NOW, responseTimeout)
.For example:
ClientRequestContext ctx = ...; // Schedules timeout after 1 seconds from now. ctx.setResponseTimeout(Duration.ofSeconds(1));
- Parameters:
responseTimeout
- the amount of time allowed from now
-
extendResponseTimeoutMillis
Deprecated.Extends the previously scheduled response timeout by the specified amount ofadjustmentMillis
. This method does nothing if no response timeout was scheduled previously. Note that a negativeadjustmentMillis
reduces the current timeout. The initial timeout is set fromClientOption.RESPONSE_TIMEOUT_MILLIS
.For example:
ClientRequestContext ctx = ...; long oldResponseTimeoutMillis = ctx.responseTimeoutMillis(); ctx.extendResponseTimeoutMillis(1000); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 1000; ctx.extendResponseTimeoutMillis(-500); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 500;
- Parameters:
adjustmentMillis
- the amount of time in milliseconds to extend the current timeout by
-
extendResponseTimeout
Deprecated.Extends the previously scheduled response timeout by the specified amount ofadjustment
. This method does nothing if no response timeout was scheduled previously. Note that a negativeadjustment
reduces the current timeout. The initial timeout is set fromClientOption.RESPONSE_TIMEOUT_MILLIS
.For example:
ClientRequestContext ctx = ...; long oldResponseTimeoutMillis = ctx.responseTimeoutMillis(); ctx.extendResponseTimeout(Duration.ofSeconds(1)); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 1000; ctx.extendResponseTimeout(Duration.ofMillis(-500)); assert ctx.responseTimeoutMillis() == oldResponseTimeoutMillis + 500;
- Parameters:
adjustment
- the amount of time to extend the current timeout by
-
setResponseTimeoutAfterMillis
Deprecated.Schedules the response timeout that is triggered when theResponse
is not fully received within the specified amount of time from now. Note that the specifiedresponseTimeoutMillis
must be positive. The initial timeout is set fromClientOption.RESPONSE_TIMEOUT_MILLIS
.For example:
ClientRequestContext ctx = ...; // Schedules timeout after 1 seconds from now. ctx.setResponseTimeoutAfterMillis(1000);
- Parameters:
responseTimeoutMillis
- the amount of time allowed in milliseconds from now
-
setResponseTimeoutAfter
Deprecated.Schedules the response timeout that is triggered when theResponse
is not fully received within the specified amount of time from now. Note that the specifiedresponseTimeout
must be positive. The initial timeout is set fromClientOption.RESPONSE_TIMEOUT_MILLIS
.For example:
ClientRequestContext ctx = ...; // Schedules timeout after 1 seconds from now. ctx.setResponseTimeoutAfter(Duration.ofSeconds(1));
- Parameters:
responseTimeout
- the amount of time allowed from now
-
setResponseTimeoutAtMillis
Deprecated.This method will be removed without a replacement. UsesetResponseTimeoutMillis(TimeoutMode, long)
}.Schedules the response timeout that is triggered at the specified time represented as the number since the epoch (1970-01-01T00:00:00Z
). Note that the response will be timed out immediately if the specified time is before now. The initial timeout is set fromClientOption.RESPONSE_TIMEOUT_MILLIS
.For example:
ClientRequestContext ctx = ...; // Schedules timeout after 1 seconds from now. long responseTimeoutAt = Instant.now().plus(1, ChronoUnit.SECONDS).toEpochMilli(); ctx.setResponseTimeoutAtMillis(responseTimeoutAt);
- Parameters:
responseTimeoutAtMillis
- the response timeout represented as the number of milliseconds since the epoch (1970-01-01T00:00:00Z
)
-
setResponseTimeoutAt
Deprecated.This method will be removed without a replacement. UsesetResponseTimeout(TimeoutMode, Duration)
.Schedules the response timeout that is triggered at the specified time represented as the number of milliseconds since the epoch (1970-01-01T00:00:00Z
). Note that the response will be timed out immediately if the specified time is before now. The initial timeout is set fromClientOption.RESPONSE_TIMEOUT_MILLIS
.For example:
ClientRequestContext ctx = ...; // Schedules timeout after 1 seconds from now. ctx.setResponseTimeoutAt(Instant.now().plus(1, ChronoUnit.SECONDS));
- Parameters:
responseTimeoutAt
- the response timeout represented as the number of milliseconds since the epoch (1970-01-01T00:00:00Z
)
-
responseTimeoutHandler
ReturnsResponse
timeout handler which is executed when theResponse
is not completely received within the allowedresponseTimeoutMillis()
or the defaultClientOption.RESPONSE_TIMEOUT_MILLIS
. -
setResponseTimeoutHandler
Sets a handler to run when the response times out.responseTimeoutHandler
must abort the response, e.g., by callingStreamMessage.abort(Throwable)
. If not set, the response will be closed withResponseTimeoutException
.For example,
HttpResponseWriter res = HttpResponse.streaming(); ctx.setResponseTimeoutHandler(() -> { res.abort(new IllegalStateException("Server is in a bad state.")); }); ...
-
maxResponseLength
long maxResponseLength()Returns the maximum length of the receivedResponse
. This value is initially set fromClientOption.MAX_RESPONSE_LENGTH
.- Returns:
- the maximum length of the response.
0
if unlimited. - See Also:
ContentTooLargeException
-
setMaxResponseLength
void setMaxResponseLength(long maxResponseLength)Sets the maximum length of the receivedResponse
. This value is initially set fromClientOption.MAX_RESPONSE_LENGTH
. Specify0
to disable the limit of the length of a response.- See Also:
ContentTooLargeException
-
additionalRequestHeaders
HttpHeaders additionalRequestHeaders() -
setAdditionalRequestHeader
Sets a header with the specifiedname
andvalue
. This will remove all previous values associated with the specifiedname
. The header will be included when aClient
sends anHttpRequest
. -
addAdditionalRequestHeader
Adds a header with the specifiedname
andvalue
. The header will be included when aClient
sends anHttpRequest
. -
mutateAdditionalRequestHeaders
- Parameters:
mutator
- theConsumer
that mutates the additional request headers
-