public class DefaultClientRequestContext extends NonWrappingRequestContext implements ClientRequestContext
ClientRequestContext implementation.| Constructor and Description |
|---|
DefaultClientRequestContext(ClientFactory factory,
MeterRegistry meterRegistry,
SessionProtocol sessionProtocol,
RequestId id,
HttpMethod method,
String path,
String query,
String fragment,
ClientOptions options,
HttpRequest req,
RpcRequest rpcReq)
Creates a new instance.
|
DefaultClientRequestContext(io.netty.channel.EventLoop eventLoop,
MeterRegistry meterRegistry,
SessionProtocol sessionProtocol,
RequestId id,
HttpMethod method,
String path,
String query,
String fragment,
ClientOptions options,
HttpRequest req,
RpcRequest rpcReq)
Creates a new 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()
|
io.netty.buffer.ByteBufAllocator |
alloc()
Returns the
ByteBufAllocator for this RequestContext. |
protected io.netty.channel.Channel |
channel()
Returns the
Channel that is handling this request, or null if the connection is not
established yet. |
Endpoint |
endpoint()
|
EndpointSelector |
endpointSelector()
Returns the
EndpointSelector used for the current Request. |
io.netty.channel.EventLoop |
eventLoop()
Returns the
EventLoop that is handling 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. |
boolean |
init(Endpoint endpoint)
Initializes this context with the specified
Endpoint. |
RequestLog |
log()
Returns the
RequestLog that contains the information about the current Request. |
RequestLogBuilder |
logBuilder()
Returns the
RequestLogBuilder that collects the information about the current Request. |
long |
maxResponseLength()
Returns the maximum length of the received
Response. |
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. |
ClientOptions |
options()
Returns the
ClientOptions of the current Request. |
boolean |
removeAdditionalRequestHeader(CharSequence name)
Removes all headers with the specified
name. |
Runnable |
responseTimeoutHandler()
Returns
Response timeout handler which is executed when
the Response is not completely received within the allowed ClientRequestContext.responseTimeoutMillis()
or the default ClientOption.RESPONSE_TIMEOUT_MILLIS. |
long |
responseTimeoutMillis()
|
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. |
SSLSession |
sslSession()
The
SSLSession for this request if the connection is made over TLS, or null if
the connection is not established yet or the connection is not a TLS connection. |
String |
toString() |
protected void |
validateHeaders(RequestHeaders headers)
Validates the specified
RequestHeaders. |
long |
writeTimeoutMillis()
Returns the amount of time allowed until the initial write attempt of the current
Request
succeeds. |
attr, attrs, decodedPath, hasAttr, id, invokeOnChildCallbacks, invokeOnEnterCallbacks, invokeOnExitCallbacks, localAddress, meterRegistry, method, onChild, onEnter, onExit, path, query, remoteAddress, request, rpcRequest, sessionProtocol, unsafeUpdateRequest, updateRequest, updateRpcRequestcontextAwareEventLoop, contextAwareExecutor, equals, executor, hashCode, isTimedOut, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, onEnter, onExit, push, push, pushIfAbsent, rejectPromise, resolvePromise, setTimedOutclone, finalize, getClass, notify, notifyAll, wait, wait, waitbuilder, builder, builder, current, currentOrNull, mapCurrent, newDerivedContext, of, of, of, request, rpcRequestattrs, contextAwareEventLoop, contextAwareExecutor, decodedPath, executor, id, invokeOnChildCallbacks, invokeOnEnterCallbacks, invokeOnExitCallbacks, isTimedOut, localAddress, 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, updateRequest, updateRpcRequestpublic DefaultClientRequestContext(io.netty.channel.EventLoop eventLoop,
MeterRegistry meterRegistry,
SessionProtocol sessionProtocol,
RequestId id,
HttpMethod method,
String path,
@Nullable
String query,
@Nullable
String fragment,
ClientOptions options,
@Nullable
HttpRequest req,
@Nullable
RpcRequest rpcReq)
init(Endpoint) method must be invoked to finish
the construction of this context.eventLoop - the EventLoop associated with this contextsessionProtocol - the SessionProtocol of the invocationid - the RequestId that represents the identifier of the current Request
and Response pair.req - the HttpRequest associated with this contextrpcReq - the RpcRequest associated with this contextpublic DefaultClientRequestContext(ClientFactory factory, MeterRegistry meterRegistry, SessionProtocol sessionProtocol, RequestId id, HttpMethod method, String path, @Nullable String query, @Nullable String fragment, ClientOptions options, @Nullable HttpRequest req, @Nullable RpcRequest rpcReq)
init(Endpoint) method must be invoked to finish
the construction of this context.factory - the ClientFactory which is used to acquire an EventLoopsessionProtocol - the SessionProtocol of the invocationid - the RequestId that contains the identifier of the current Request
and Response pair.req - the HttpRequest associated with this contextrpcReq - the RpcRequest associated with this contextpublic boolean init(Endpoint endpoint)
Endpoint.
This method must be invoked to finish the construction of this context.true if the initialization has succeeded.
false if the initialization has failed and this context's RequestLog has been
completed with the cause of the failure.public ClientRequestContext newDerivedContext(RequestId id, @Nullable HttpRequest req, @Nullable RpcRequest rpcReq, Endpoint endpoint)
ClientRequestContextClientRequestContext whose properties and Attributes are copied from this
ClientRequestContext, except having different Request, Endpoint and its own
RequestLog.newDerivedContext in interface ClientRequestContextprotected void validateHeaders(RequestHeaders headers)
NonWrappingRequestContextRequestHeaders. By default, this method will raise
an IllegalArgumentException if it does not have ":scheme" or ":authority"
header.validateHeaders in class NonWrappingRequestContext@Nullable protected io.netty.channel.Channel channel()
NonWrappingRequestContextChannel that is handling this request, or null if the connection is not
established yet.channel in class NonWrappingRequestContextpublic io.netty.channel.EventLoop eventLoop()
RequestContextEventLoop that is handling the current Request.eventLoop in interface RequestContext@Nullable public SSLSession sslSession()
RequestContextSSLSession for this request if the connection is made over TLS, or null if
the connection is not established yet or the connection is not a TLS connection.sslSession in interface RequestContextpublic ClientOptions options()
ClientRequestContextClientOptions of the current Request.options in interface ClientRequestContextpublic EndpointSelector endpointSelector()
ClientRequestContextEndpointSelector used for the current Request.endpointSelector in interface ClientRequestContextEndpointSelector if a user specified a group Endpoint.
null if a user specified a host Endpoint.public Endpoint endpoint()
ClientRequestContextendpoint in interface ClientRequestContextEndpoint. null if the Request has failed
because its remote Endpoint couldn't be determined.@Nullable public String fragment()
ClientRequestContextRequest, as defined in
the section 3.5 of RFC3986.fragment in interface ClientRequestContextnull if no fragment was specifiedpublic long writeTimeoutMillis()
ClientRequestContextRequest
succeeds. This value is initially set from ClientOption.WRITE_TIMEOUT_MILLIS.writeTimeoutMillis in interface ClientRequestContextpublic void setWriteTimeoutMillis(long writeTimeoutMillis)
ClientRequestContextRequest
succeeds. This value is initially set from ClientOption.WRITE_TIMEOUT_MILLIS.setWriteTimeoutMillis in interface ClientRequestContextpublic void setWriteTimeout(Duration writeTimeout)
ClientRequestContextRequest
succeeds. This value is initially set from ClientOption.WRITE_TIMEOUT_MILLIS.setWriteTimeout in interface ClientRequestContextpublic long responseTimeoutMillis()
ClientRequestContextResponse completely
since the transfer of the Response started. This value is initially set from
ClientOption.RESPONSE_TIMEOUT_MILLIS.responseTimeoutMillis in interface ClientRequestContextpublic void setResponseTimeoutMillis(long responseTimeoutMillis)
ClientRequestContextResponse completely
since the transfer of the Response started. This value is initially set from
ClientOption.RESPONSE_TIMEOUT_MILLIS.setResponseTimeoutMillis in interface ClientRequestContextpublic void setResponseTimeout(Duration responseTimeout)
ClientRequestContextResponse completely
since the transfer of the Response started. This value is initially set from
ClientOption.RESPONSE_TIMEOUT_MILLIS.setResponseTimeout in interface ClientRequestContext@Nullable public Runnable responseTimeoutHandler()
ClientRequestContextResponse timeout handler which is executed when
the Response is not completely received within the allowed ClientRequestContext.responseTimeoutMillis()
or the default ClientOption.RESPONSE_TIMEOUT_MILLIS.responseTimeoutHandler in interface ClientRequestContextpublic void setResponseTimeoutHandler(Runnable responseTimeoutHandler)
ClientRequestContextresponseTimeoutHandler 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."));
});
...
setResponseTimeoutHandler in interface ClientRequestContextpublic long maxResponseLength()
ClientRequestContextResponse.
This value is initially set from ClientOption.MAX_RESPONSE_LENGTH.maxResponseLength in interface ClientRequestContextContentTooLargeExceptionpublic void setMaxResponseLength(long maxResponseLength)
ClientRequestContextResponse.
This value is initially set from ClientOption.MAX_RESPONSE_LENGTH.setMaxResponseLength in interface ClientRequestContextContentTooLargeExceptionpublic HttpHeaders additionalRequestHeaders()
ClientRequestContextadditionalRequestHeaders in interface ClientRequestContextpublic void setAdditionalRequestHeader(CharSequence name, Object value)
ClientRequestContextname and value. This will remove all previous values
associated with the specified name.
The header will be included when a Client sends an HttpRequest.setAdditionalRequestHeader in interface ClientRequestContextpublic void setAdditionalRequestHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
ClientRequestContextHttpHeaders which is included when a
Client sends an HttpRequest.setAdditionalRequestHeaders in interface ClientRequestContextpublic void addAdditionalRequestHeader(CharSequence name, Object value)
ClientRequestContextname and value. The header will be included when
a Client sends an HttpRequest.addAdditionalRequestHeader in interface ClientRequestContextpublic void addAdditionalRequestHeaders(Iterable<? extends Map.Entry<? extends CharSequence,?>> headers)
ClientRequestContextaddAdditionalRequestHeaders in interface ClientRequestContextpublic boolean removeAdditionalRequestHeader(CharSequence name)
ClientRequestContextname.removeAdditionalRequestHeader in interface ClientRequestContexttrue if at least one entry has been removedpublic RequestLog log()
RequestContextRequestLog that contains the information about the current Request.log in interface RequestContextpublic RequestLogBuilder logBuilder()
RequestContextRequestLogBuilder that collects the information about the current Request.logBuilder in interface RequestContextpublic io.netty.buffer.ByteBufAllocator alloc()
RequestContextByteBufAllocator for this RequestContext. Any buffers created by this
ByteBufAllocator must be
reference-counted. If you don't know
what this means, you should probably use byte[] or ByteBuffer directly instead
of calling this method.alloc in interface RequestContextCopyright © 2020 LeanCloud. All rights reserved.