接口 ServerWebExchange
public interface ServerWebExchange
Contract for an HTTP request-response interaction. Provides access to the HTTP request and response and also exposes additional server-side processing related properties and features such as request attributes.- 从以下版本开始:
- 5.0
- 作者:
- Rossen Stoyanchev
嵌套类概要
嵌套类 修饰符和类型 接口 说明 static interface
ServerWebExchange.Builder
Builder for mutating an existingServerWebExchange
.
字段概要
字段 修饰符和类型 字段 说明 static String
LOG_ID_ATTRIBUTE
Name ofattribute
whose value can be used to correlate log messages for this exchange.
方法概要
所有方法 实例方法 抽象方法 默认方法 修饰符和类型 方法 说明 void
addUrlTransformer(Function<String,String> transformer)
Register an additional URL transformation function for use withtransformUrl(java.lang.String)
.boolean
checkNotModified(String etag)
An overloaded variant ofcheckNotModified(String, Instant)
with anETag
(entity tag) value only.boolean
checkNotModified(String etag, Instant lastModified)
Check whether the requested resource has been modified given the suppliedETag
(entity tag) and last-modified timestamp as determined by the application.boolean
checkNotModified(Instant lastModified)
An overloaded variant ofcheckNotModified(String, Instant)
with a last-modified timestamp only.ApplicationContext
getApplicationContext()
Return theApplicationContext
associated with the web application, if it was initialized with one viaWebHttpHandlerBuilder.applicationContext(ApplicationContext)
.default <T> T
getAttribute(String name)
Return the request attribute value if present.default <T> T
getAttributeOrDefault(String name, T defaultValue)
Return the request attribute value, or a default, fallback value.Map<String,Object>
getAttributes()
Return a mutable map of request attributes for the current exchange.reactor.core.publisher.Mono<MultiValueMap<String,String>>
getFormData()
Return the form data from the body of the request if the Content-Type is"application/x-www-form-urlencoded"
or an empty map otherwise.LocaleContext
getLocaleContext()
Return theLocaleContext
using the configuredLocaleContextResolver
.String
getLogPrefix()
Return a log message prefix to use to correlate messages for this exchange.reactor.core.publisher.Mono<MultiValueMap<String,Part>>
getMultipartData()
Return the parts of a multipart request if the Content-Type is"multipart/form-data"
or an empty map otherwise.<T extends Principal>
reactor.core.publisher.Mono<T>getPrincipal()
Return the authenticated user for the request, if any.ServerHttpRequest
getRequest()
Return the current HTTP request.default <T> T
getRequiredAttribute(String name)
Return the request attribute value or if not present raise anIllegalArgumentException
.ServerHttpResponse
getResponse()
Return the current HTTP response.reactor.core.publisher.Mono<WebSession>
getSession()
Return the web session for the current request.boolean
isNotModified()
Returnstrue
if the one of thecheckNotModified
methods in this contract were used and they returned true.default ServerWebExchange.Builder
mutate()
Return a builder to mutate properties of this exchange by wrapping it withServerWebExchangeDecorator
and returning either mutated values or delegating back to this instance.String
transformUrl(String url)
Transform the given url according to the registered transformation function(s).
字段详细资料
LOG_ID_ATTRIBUTE
static final String LOG_ID_ATTRIBUTE
Name ofattribute
whose value can be used to correlate log messages for this exchange. UsegetLogPrefix()
to obtain a consistently formatted prefix based on this attribute.- 从以下版本开始:
- 5.1
- 另请参阅:
getLogPrefix()
方法详细资料
getRequest
ServerHttpRequest getRequest()
Return the current HTTP request.
getResponse
ServerHttpResponse getResponse()
Return the current HTTP response.
getAttributes
Map<String,Object> getAttributes()
Return a mutable map of request attributes for the current exchange.
getAttribute
@Nullable default <T> T getAttribute(String name)
Return the request attribute value if present.- 类型参数:
T
- the attribute type- 参数:
name
- the attribute name- 返回:
- the attribute value
getRequiredAttribute
default <T> T getRequiredAttribute(String name)
Return the request attribute value or if not present raise anIllegalArgumentException
.- 类型参数:
T
- the attribute type- 参数:
name
- the attribute name- 返回:
- the attribute value
getAttributeOrDefault
default <T> T getAttributeOrDefault(String name, T defaultValue)
Return the request attribute value, or a default, fallback value.- 类型参数:
T
- the attribute type- 参数:
name
- the attribute namedefaultValue
- a default value to return instead- 返回:
- the attribute value
getSession
reactor.core.publisher.Mono<WebSession> getSession()
Return the web session for the current request. Always guaranteed to return an instance either matching to the session id requested by the client, or with a new session id either because the client did not specify one or because the underlying session had expired. Use of this method does not automatically create a session. SeeWebSession
for more details.
getPrincipal
<T extends Principal> reactor.core.publisher.Mono<T> getPrincipal()
Return the authenticated user for the request, if any.
getFormData
reactor.core.publisher.Mono<MultiValueMap<String,String>> getFormData()
Return the form data from the body of the request if the Content-Type is"application/x-www-form-urlencoded"
or an empty map otherwise.Note: calling this method causes the request body to be read and parsed in full and the resulting
MultiValueMap
is cached so that this method is safe to call more than once.
getMultipartData
reactor.core.publisher.Mono<MultiValueMap<String,Part>> getMultipartData()
Return the parts of a multipart request if the Content-Type is"multipart/form-data"
or an empty map otherwise.Note: calling this method causes the request body to be read and parsed in full and the resulting
MultiValueMap
is cached so that this method is safe to call more than once.Note:the contents of each part is not cached, and can only be read once.
getLocaleContext
LocaleContext getLocaleContext()
Return theLocaleContext
using the configuredLocaleContextResolver
.
getApplicationContext
@Nullable ApplicationContext getApplicationContext()
Return theApplicationContext
associated with the web application, if it was initialized with one viaWebHttpHandlerBuilder.applicationContext(ApplicationContext)
.- 从以下版本开始:
- 5.0.3
- 另请参阅:
WebHttpHandlerBuilder.applicationContext(ApplicationContext)
isNotModified
boolean isNotModified()
Returnstrue
if the one of thecheckNotModified
methods in this contract were used and they returned true.
checkNotModified
boolean checkNotModified(Instant lastModified)
An overloaded variant ofcheckNotModified(String, Instant)
with a last-modified timestamp only.- 参数:
lastModified
- the last-modified time- 返回:
- whether the request qualifies as not modified
checkNotModified
boolean checkNotModified(String etag)
An overloaded variant ofcheckNotModified(String, Instant)
with anETag
(entity tag) value only.- 参数:
etag
- the entity tag for the underlying resource.- 返回:
- true if the request does not require further processing.
checkNotModified
boolean checkNotModified(@Nullable String etag, Instant lastModified)
Check whether the requested resource has been modified given the suppliedETag
(entity tag) and last-modified timestamp as determined by the application. Also transparently prepares the response, setting HTTP status, and adding "ETag" and "Last-Modified" headers when applicable. This method works with conditional GET/HEAD requests as well as with conditional POST/PUT/DELETE requests.Note: The HTTP specification recommends setting both ETag and Last-Modified values, but you can also use
#checkNotModified(String)
orcheckNotModified(Instant)
.- 参数:
etag
- the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.lastModified
- the last-modified timestamp that the application determined for the underlying resource- 返回:
- true if the request does not require further processing.
transformUrl
String transformUrl(String url)
Transform the given url according to the registered transformation function(s). By default, this method returns the givenurl
, though additional transformation functions can by registered withaddUrlTransformer(java.util.function.Function<java.lang.String, java.lang.String>)
- 参数:
url
- the URL to transform- 返回:
- the transformed URL
addUrlTransformer
void addUrlTransformer(Function<String,String> transformer)
Register an additional URL transformation function for use withtransformUrl(java.lang.String)
. The given function can be used to insert an id for authentication, a nonce for CSRF protection, etc.Note that the given function is applied after any previously registered functions.
- 参数:
transformer
- a URL transformation function to add
getLogPrefix
String getLogPrefix()
Return a log message prefix to use to correlate messages for this exchange. The prefix is based on the value of the attributeLOG_ID_ATTRIBUTE
along with some extra formatting so that the prefix can be conveniently prepended with no further formatting no separators required.- 返回:
- the log message prefix or an empty String if the
LOG_ID_ATTRIBUTE
is not set. - 从以下版本开始:
- 5.1
mutate
default ServerWebExchange.Builder mutate()
Return a builder to mutate properties of this exchange by wrapping it withServerWebExchangeDecorator
and returning either mutated values or delegating back to this instance.