Package com.linecorp.armeria.server
Interface ServiceRequestContext
-
- All Superinterfaces:
AttributeMap
,RequestContext
- All Known Implementing Classes:
DefaultServiceRequestContext
,ServiceRequestContextWrapper
public interface ServiceRequestContext extends RequestContext
Provides information about an invocation and related utilities. Every request being handled has its ownServiceRequestContext
instance.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
addAdditionalResponseHeader(AsciiString name, String value)
Adds a header with the specifiedname
andvalue
.void
addAdditionalResponseHeaders(Headers<? extends AsciiString,? extends String,?> headers)
HttpHeaders
additionalResponseHeaders()
ExecutorService
blockingTaskExecutor()
Returns theExecutorService
that could be used for executing a potentially long-running task.<A extends SocketAddress>
AlocalAddress()
Returns the local address of this request.Logger
logger()
Deprecated.Use a logging framework integration such asRequestContextExportingAppender
inarmeria-logback
.String
mappedPath()
Returns the path with its context path removed.long
maxRequestLength()
Returns the maximum length of the currentRequest
.default MediaType
negotiatedProduceType()
Deprecated.MediaType
negotiatedResponseMediaType()
Returns the negotiated producible media type.ServiceRequestContext
newDerivedContext()
Creates a new derivedRequestContext
which only theRequestLog
is different from the deriving context.ServiceRequestContext
newDerivedContext(Request request)
Creates a new derivedRequestContext
with the specifiedRequest
which theRequestLog
is different from the deriving context.PathMapping
pathMapping()
PathMappingContext
pathMappingContext()
Returns thePathMappingContext
used to find theService
.default String
pathParam(String name)
Returns the value of the specified path parameter.Map<String,String>
pathParams()
Returns the path parameters mapped by thePathMapping
associated with theService
that is handling the currentRequest
.ProxiedAddresses
proxiedAddresses()
Returns the proxied addresses if the currentRequest
is received through a proxy.<A extends SocketAddress>
AremoteAddress()
Returns the remote address of this request.boolean
removeAdditionalResponseHeader(AsciiString name)
Removes all headers with the specifiedname
.long
requestTimeoutMillis()
Returns the amount of time allowed until receiving the currentRequest
completely.Server
server()
<T extends Service<HttpRequest,HttpResponse>>
Tservice()
void
setAdditionalResponseHeader(AsciiString name, String value)
Sets a header with the specifiedname
andvalue
.void
setAdditionalResponseHeaders(Headers<? extends AsciiString,? extends String,?> headers)
Clears the current header and sets the specifiedHeaders
which is included when aService
sends anHttpResponse
.void
setMaxRequestLength(long maxRequestLength)
Sets the maximum length of the currentRequest
.void
setRequestTimeout(Duration requestTimeout)
Sets the amount of time allowed until receiving the currentRequest
completely.void
setRequestTimeoutHandler(Runnable requestTimeoutHandler)
Sets a handler to run when the request times out.void
setRequestTimeoutMillis(long requestTimeoutMillis)
Sets the amount of time allowed until receiving the currentRequest
completely.VirtualHost
virtualHost()
Returns theVirtualHost
that is handling the currentRequest
.-
Methods inherited from interface io.netty.util.AttributeMap
attr, hasAttr
-
Methods inherited from interface com.linecorp.armeria.common.RequestContext
alloc, attrs, contextAwareEventLoop, contextAwareExecutor, eventLoop, executor, invokeOnChildCallbacks, invokeOnEnterCallbacks, invokeOnExitCallbacks, isTimedOut, log, logBuilder, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, makeContextAware, meterRegistry, method, onChild, onEnter, onEnter, onExit, onExit, path, push, push, pushIfAbsent, query, rejectPromise, request, resolvePromise, sessionProtocol, sslSession
-
-
-
-
Method Detail
-
remoteAddress
@Nonnull <A extends SocketAddress> A remoteAddress()
Returns the remote address of this request.- Specified by:
remoteAddress
in interfaceRequestContext
-
localAddress
@Nonnull <A extends SocketAddress> A localAddress()
Returns the local address of this request.- Specified by:
localAddress
in interfaceRequestContext
-
newDerivedContext
ServiceRequestContext newDerivedContext()
Description copied from interface:RequestContext
Creates a new derivedRequestContext
which only theRequestLog
is different from the deriving context. Note that the references ofAttribute
s in theRequestContext.attrs()
are copied as well.- Specified by:
newDerivedContext
in interfaceRequestContext
-
newDerivedContext
ServiceRequestContext newDerivedContext(Request request)
Description copied from interface:RequestContext
Creates a new derivedRequestContext
with the specifiedRequest
which theRequestLog
is different from the deriving context. Note that the references ofAttribute
s in theRequestContext.attrs()
are copied as well.- Specified by:
newDerivedContext
in interfaceRequestContext
-
server
Server server()
-
virtualHost
VirtualHost virtualHost()
Returns theVirtualHost
that is handling the currentRequest
.
-
pathMapping
PathMapping pathMapping()
-
pathMappingContext
PathMappingContext pathMappingContext()
Returns thePathMappingContext
used to find theService
.
-
pathParams
Map<String,String> pathParams()
Returns the path parameters mapped by thePathMapping
associated with theService
that is handling the currentRequest
.
-
pathParam
@Nullable default String pathParam(String name)
Returns the value of the specified path parameter.
-
service
<T extends Service<HttpRequest,HttpResponse>> T service()
-
blockingTaskExecutor
ExecutorService blockingTaskExecutor()
Returns theExecutorService
that could be used for executing a potentially long-running task. TheExecutorService
will propagate theServiceRequestContext
automatically when running a task.Note that performing a long-running task in
Service.serve(ServiceRequestContext, Request)
may block theServer
's I/O event loop and thus should be executed in other threads.
-
mappedPath
String mappedPath()
Returns the path with its context path removed. This method can be useful for a reusable service bound at various path prefixes.
-
negotiatedResponseMediaType
@Nullable MediaType negotiatedResponseMediaType()
Returns the negotiated producible media type. If the media type negotiation is not used for theService
,null
would be returned.
-
negotiatedProduceType
@Deprecated @Nullable default MediaType negotiatedProduceType()
Deprecated.Returns the negotiated producible media type. If the media type negotiation is not used for theService
,null
would be returned.
-
logger
@Deprecated Logger logger()
Deprecated.Use a logging framework integration such asRequestContextExportingAppender
inarmeria-logback
.
-
requestTimeoutMillis
long requestTimeoutMillis()
Returns the amount of time allowed until receiving the currentRequest
completely. This value is initially set fromServerConfig.defaultRequestTimeoutMillis()
.
-
setRequestTimeoutMillis
void setRequestTimeoutMillis(long requestTimeoutMillis)
Sets the amount of time allowed until receiving the currentRequest
completely. This value is initially set fromServerConfig.defaultRequestTimeoutMillis()
.
-
setRequestTimeout
void setRequestTimeout(Duration requestTimeout)
Sets the amount of time allowed until receiving the currentRequest
completely. This value is initially set fromServerConfig.defaultRequestTimeoutMillis()
.
-
setRequestTimeoutHandler
void setRequestTimeoutHandler(Runnable requestTimeoutHandler)
Sets a handler to run when the request times out.requestTimeoutHandler
must close the response, e.g., by callingStreamWriter.close()
. If not set, the response will be closed withHttpStatus.SERVICE_UNAVAILABLE
.For example,
HttpResponseWriter res = HttpResponse.streaming(); ctx.setRequestTimeoutHandler(() -> { res.write(HttpHeaders.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, "Request timed out.")); res.close(); }); ...
-
maxRequestLength
long maxRequestLength()
Returns the maximum length of the currentRequest
. This value is initially set fromServerConfig.defaultMaxRequestLength()
. If 0, there is no limit on the request size.- See Also:
ContentTooLargeException
-
setMaxRequestLength
void setMaxRequestLength(long maxRequestLength)
Sets the maximum length of the currentRequest
. This value is initially set fromServerConfig.defaultMaxRequestLength()
. If 0, there is no limit on the request size.- See Also:
ContentTooLargeException
-
additionalResponseHeaders
HttpHeaders additionalResponseHeaders()
-
setAdditionalResponseHeader
void setAdditionalResponseHeader(AsciiString name, String value)
Sets a header with the specifiedname
andvalue
. This will remove all previous values associated with the specifiedname
. The header will be included when aService
sends anHttpResponse
.
-
setAdditionalResponseHeaders
void setAdditionalResponseHeaders(Headers<? extends AsciiString,? extends String,?> headers)
Clears the current header and sets the specifiedHeaders
which is included when aService
sends anHttpResponse
.
-
addAdditionalResponseHeader
void addAdditionalResponseHeader(AsciiString name, String value)
Adds a header with the specifiedname
andvalue
. The header will be included when aService
sends anHttpResponse
.
-
addAdditionalResponseHeaders
void addAdditionalResponseHeaders(Headers<? extends AsciiString,? extends String,?> headers)
-
removeAdditionalResponseHeader
boolean removeAdditionalResponseHeader(AsciiString name)
Removes all headers with the specifiedname
.- Returns:
true
if at least one entry has been removed
-
proxiedAddresses
@Nullable ProxiedAddresses proxiedAddresses()
Returns the proxied addresses if the currentRequest
is received through a proxy.
-
-