public interface ClientRequestContext extends RequestContext
Request, its Response and its related utilities.
Every client request has its own ClientRequestContext instance.| Modifier and Type | Method and Description |
|---|---|
void |
addAdditionalRequestHeader(CharSequence name,
Object value)
Adds a header with the specified
name and value. |
void |
addAdditionalRequestHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
|
HttpHeaders |
additionalRequestHeaders()
|
static ClientRequestContextBuilder |
builder(HttpRequest request)
Returns a new
ClientRequestContextBuilder created from the specified HttpRequest. |
static ClientRequestContextBuilder |
builder(RpcRequest request,
String uri)
|
static ClientRequestContextBuilder |
builder(RpcRequest request,
URI uri)
|
static ClientRequestContext |
current()
Returns the client-side context of the
Request that is being handled in the current thread. |
static ClientRequestContext |
currentOrNull()
Returns the client-side context of the
Request that is being handled in the current thread. |
Endpoint |
endpoint()
|
EndpointSelector |
endpointSelector()
Returns the
EndpointSelector used for the current Request. |
String |
fragment()
Returns the fragment part of the URI of the current
Request, 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 the
Request that is being handled in the current thread. |
long |
maxResponseLength()
Returns the maximum length of the received
Response. |
default ClientRequestContext |
newDerivedContext(RequestId id,
HttpRequest req,
RpcRequest rpcReq)
Creates a new
ClientRequestContext whose properties and Attributes are copied from this
ClientRequestContext, except having a different Request and its own RequestLog. |
ClientRequestContext |
newDerivedContext(RequestId id,
HttpRequest req,
RpcRequest rpcReq,
Endpoint endpoint)
Creates a new
ClientRequestContext whose properties and Attributes are copied from this
ClientRequestContext, except having different Request, Endpoint and its own
RequestLog. |
static ClientRequestContext |
of(HttpRequest request)
Returns a new
ClientRequestContext created from the specified HttpRequest. |
static ClientRequestContext |
of(RpcRequest request,
String uri)
Returns a new
ClientRequestContext created from the specified RpcRequest and URI. |
static ClientRequestContext |
of(RpcRequest request,
URI uri)
|
ClientOptions |
options()
Returns the
ClientOptions of the current Request. |
boolean |
removeAdditionalRequestHeader(CharSequence name)
Removes all headers with the specified
name. |
HttpRequest |
request()
Returns the
HttpRequest associated with this context, or null if there's no
HttpRequest associated with this context yet. |
Runnable |
responseTimeoutHandler()
Returns
Response timeout handler which is executed when
the Response is not completely received within the allowed responseTimeoutMillis()
or the default ClientOption.RESPONSE_TIMEOUT_MILLIS. |
long |
responseTimeoutMillis()
|
RpcRequest |
rpcRequest()
Returns the
RpcRequest associated with this context, or null if there's no
RpcRequest associated with this context. |
void |
setAdditionalRequestHeader(CharSequence name,
Object value)
Sets a header with the specified
name and value. |
void |
setAdditionalRequestHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
Clears the current header and sets the specified
HttpHeaders which is included when a
Client sends an HttpRequest. |
void |
setMaxResponseLength(long maxResponseLength)
Sets the maximum length of the received
Response. |
void |
setResponseTimeout(Duration responseTimeout)
|
void |
setResponseTimeoutHandler(Runnable responseTimeoutHandler)
Sets a handler to run when the response times out.
|
void |
setResponseTimeoutMillis(long responseTimeoutMillis)
|
void |
setWriteTimeout(Duration writeTimeout)
Returns the amount of time allowed until the initial write attempt of the current
Request
succeeds. |
void |
setWriteTimeoutMillis(long writeTimeoutMillis)
Returns the amount of time allowed until the initial write attempt of the current
Request
succeeds. |
long |
writeTimeoutMillis()
Returns the amount of time allowed until the initial write attempt of the current
Request
succeeds. |
alloc, attrs, contextAwareEventLoop, contextAwareExecutor, decodedPath, eventLoop, executor, id, invokeOnChildCallbacks, invokeOnEnterCallbacks, invokeOnExitCallbacks, isTimedOut, localAddress, log, logBuilder, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, mapCurrent, meterRegistry, method, onChild, onEnter, onEnter, onExit, onExit, path, push, push, push, push, pushIfAbsent, query, rejectPromise, remoteAddress, resolvePromise, sessionProtocol, sslSession, updateRequest, updateRpcRequeststatic ClientRequestContext current()
Request that is being handled in the current thread.current in interface RequestContextIllegalStateException - if the context is unavailable in the current thread or
the current context is not a ClientRequestContext.@Nullable static ClientRequestContext currentOrNull()
Request that is being handled in the current thread.currentOrNull in interface RequestContextClientRequestContext available in the current thread, or null if unavailable.IllegalStateException - if the current context is not a ClientRequestContext.@Nullable static <T> T mapCurrent(Function<? super ClientRequestContext,T> mapper, @Nullable Supplier<T> defaultValueSupplier)
Request that is being handled in the current thread.mapper - the Function that maps the ClientRequestContextdefaultValueSupplier - the Supplier that provides the value when the context is unavailable
in the current thread. If null, the null will be returned
when the context is unavailable in the current thread.IllegalStateException - if the current context is not a ClientRequestContext.static ClientRequestContext of(HttpRequest request)
ClientRequestContext created from the specified HttpRequest.
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.ClientRequestContextBuilderstatic ClientRequestContext of(RpcRequest request, String uri)
ClientRequestContext created from the specified RpcRequest 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.ClientRequestContextBuilderstatic ClientRequestContext of(RpcRequest request, URI uri)
ClientRequestContext created from the specified RpcRequest 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.ClientRequestContextBuilderstatic ClientRequestContextBuilder builder(HttpRequest request)
ClientRequestContextBuilder created from the specified HttpRequest.static ClientRequestContextBuilder builder(RpcRequest request, String uri)
static ClientRequestContextBuilder builder(RpcRequest request, URI uri)
@Nullable HttpRequest request()
HttpRequest associated with this context, or null if there's no
HttpRequest associated with this context yet. For example, when you send an RPC request, this method will return null until
the RPC request is translated into an HTTP request.request in interface RequestContext@Nullable RpcRequest rpcRequest()
RpcRequest associated with this context, or null if there's no
RpcRequest associated with this context. For example, this method will return null when you are not sending an RPC request
but just a plain HTTP request.rpcRequest in interface RequestContextdefault ClientRequestContext newDerivedContext(RequestId id, @Nullable HttpRequest req, @Nullable RpcRequest rpcReq)
ClientRequestContext whose properties and Attributes are copied from this
ClientRequestContext, except having a different Request and its own RequestLog.newDerivedContext in interface RequestContextClientRequestContext newDerivedContext(RequestId id, @Nullable HttpRequest req, @Nullable RpcRequest rpcReq, Endpoint endpoint)
ClientRequestContext whose properties and Attributes are copied from this
ClientRequestContext, except having different Request, Endpoint and its own
RequestLog.@Nullable EndpointSelector endpointSelector()
EndpointSelector used for the current Request.EndpointSelector if a user specified a group Endpoint.
null if a user specified a host Endpoint.ClientOptions options()
ClientOptions of the current Request.@Nullable String fragment()
Request, as defined in
the section 3.5 of RFC3986.null if no fragment was specifiedlong writeTimeoutMillis()
Request
succeeds. This value is initially set from ClientOption.WRITE_TIMEOUT_MILLIS.void setWriteTimeoutMillis(long writeTimeoutMillis)
Request
succeeds. This value is initially set from ClientOption.WRITE_TIMEOUT_MILLIS.void setWriteTimeout(Duration writeTimeout)
Request
succeeds. This value is initially set from ClientOption.WRITE_TIMEOUT_MILLIS.long responseTimeoutMillis()
Response completely
since the transfer of the Response started. This value is initially set from
ClientOption.RESPONSE_TIMEOUT_MILLIS.void setResponseTimeoutMillis(long responseTimeoutMillis)
Response completely
since the transfer of the Response started. This value is initially set from
ClientOption.RESPONSE_TIMEOUT_MILLIS.void setResponseTimeout(Duration responseTimeout)
Response completely
since the transfer of the Response started. This value is initially set from
ClientOption.RESPONSE_TIMEOUT_MILLIS.@Nullable Runnable responseTimeoutHandler()
Response timeout handler which is executed when
the Response is not completely received within the allowed responseTimeoutMillis()
or the default ClientOption.RESPONSE_TIMEOUT_MILLIS.void setResponseTimeoutHandler(Runnable responseTimeoutHandler)
responseTimeoutHandler must abort
the response, e.g., by calling StreamMessage.abort(Throwable).
If not set, the response will be closed with ResponseTimeoutException.
For example,
HttpResponseWriter res = HttpResponse.streaming();
ctx.setResponseTimeoutHandler(() -> {
res.abort(new IllegalStateException("Server is in a bad state."));
});
...
long maxResponseLength()
Response.
This value is initially set from ClientOption.MAX_RESPONSE_LENGTH.ContentTooLargeExceptionvoid setMaxResponseLength(long maxResponseLength)
Response.
This value is initially set from ClientOption.MAX_RESPONSE_LENGTH.ContentTooLargeExceptionHttpHeaders additionalRequestHeaders()
void setAdditionalRequestHeader(CharSequence name, Object value)
name and value. This will remove all previous values
associated with the specified name.
The header will be included when a Client sends an HttpRequest.void setAdditionalRequestHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
HttpHeaders which is included when a
Client sends an HttpRequest.void addAdditionalRequestHeader(CharSequence name, Object value)
name and value. The header will be included when
a Client sends an HttpRequest.void addAdditionalRequestHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
boolean removeAdditionalRequestHeader(CharSequence name)
name.true if at least one entry has been removedCopyright © 2020 LeanCloud. All rights reserved.