接口 ServerRequest
- 所有超级接口:
ServerResponse.Context
- 所有已知实现类:
DefaultServerRequest,DefaultServerRequestBuilder.BuiltServerRequest,RequestPredicates.SubPathServerRequestWrapper
HandlerFunction.
Access to headers and body is offered by ServerRequest.Headers and
body(Class), respectively.- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Harry Yang
-
嵌套类概要
嵌套类修饰符和类型接口说明static interfaceDefines a builder for a request.static interfaceRepresents the headers of the HTTP request. -
方法概要
修饰符和类型方法说明Get the request attribute value if present.Get a mutable map of request attributes.default <T> TBind to this request and return an instance of the given type.<T> Tbind(Class<T> bindType, Consumer<WebDataBinder> dataBinderCustomizer) Bind to this request and return an instance of the given type.<T> Tbody(cn.taketoday.core.ParameterizedTypeReference<T> bodyType) Extract the body as an object of the given type.<T> TExtract the body as an object of the given type.default Optional<ServerResponse>checkNotModified(String etag) Check whether the requested resource has been modified given the suppliedETag(entity tag), as determined by the application.default Optional<ServerResponse>checkNotModified(Instant lastModified) Check whether the requested resource has been modified given the supplied last-modified timestamp (as determined by the application).default Optional<ServerResponse>checkNotModified(Instant lastModified, String etag) Check whether the requested resource has been modified given the suppliedETag(entity tag) and last-modified timestamp, as determined by the application.cn.taketoday.util.MultiValueMap<String,HttpCookie> cookies()Get the cookies of this request.static ServerRequestcreate(RequestContext context, List<HttpMessageConverter<?>> messageReaders) Create a newServerRequestbased on the givenRequestContextand message converters.exchange()Get the request that this request is based on.static ServerRequestfind(RequestContext context) static ServerRequestfindRequired(RequestContext context) static ServerRequest.Builderfrom(ServerRequest other) Create a builder with the status, headers, and cookies of the given request.headers()Get the headers of this request.Get the readers used to convert the body of this request.method()Get the HTTP method.Get the name of the HTTP method.Get the parts of a multipart request, provided the Content-Type is"multipart/form-data", or an exception otherwise.Get the first parameter with the given name, if present.params()Get all parameters for this request. parameters are contained in the query string or posted form data.Get the parameters with the given name.default Stringpath()Get the request path.default StringpathVariable(String name) Get the path variable with the given name, if present.Get all path variables for this request.Get the remote address to which this request is connected, if available.default RequestPathGet the request path as aPathContainer.uri()Get the request URI.Get aUriBuilderComponentsfrom the URI associated with thisServerRequest.
-
方法详细资料
-
method
HttpMethod method()Get the HTTP method.- 返回:
- the HTTP method as an HttpMethod enum value, or
nullif not resolvable (e.g. in case of a non-standard HTTP method)
-
methodName
String methodName()Get the name of the HTTP method.- 返回:
- the HTTP method as a String
-
uri
URI uri()Get the request URI. -
uriBuilder
UriBuilder uriBuilder()Get aUriBuilderComponentsfrom the URI associated with thisServerRequest.- 返回:
- a URI builder
-
path
Get the request path. -
requestPath
Get the request path as aPathContainer. -
headers
ServerRequest.Headers headers()Get the headers of this request. -
cookies
cn.taketoday.util.MultiValueMap<String,HttpCookie> cookies()Get the cookies of this request. -
remoteAddress
Optional<InetSocketAddress> remoteAddress()Get the remote address to which this request is connected, if available. -
messageConverters
List<HttpMessageConverter<?>> messageConverters()Get the readers used to convert the body of this request.- 指定者:
messageConverters在接口中ServerResponse.Context- 返回:
- the list of message writers
-
body
Extract the body as an object of the given type.- 类型参数:
T- the body type- 参数:
bodyType- the type of return value- 返回:
- the body
- 抛出:
IOException
-
body
Extract the body as an object of the given type.- 类型参数:
T- the body type- 参数:
bodyType- the type of return value- 返回:
- the body
- 抛出:
IOException
-
bind
Bind to this request and return an instance of the given type.- 类型参数:
T- the type to bind to- 参数:
bindType- the type of class to bind this request to- 返回:
- a constructed and bound instance of
bindType - 抛出:
cn.taketoday.validation.BindException- in case of binding errors
-
bind
<T> T bind(Class<T> bindType, Consumer<WebDataBinder> dataBinderCustomizer) throws cn.taketoday.validation.BindException Bind to this request and return an instance of the given type.- 类型参数:
T- the type to bind to- 参数:
bindType- the type of class to bind this request todataBinderCustomizer- used to customize the data binder, e.g. set (dis)allowed fields- 返回:
- a constructed and bound instance of
bindType - 抛出:
cn.taketoday.validation.BindException- in case of binding errors
-
attribute
Get the request attribute value if present.- 参数:
name- the attribute name- 返回:
- the attribute value
-
attributes
Get a mutable map of request attributes.- 返回:
- the request attributes
-
param
Get the first parameter with the given name, if present. parameters are contained in the query string or posted form data.- 参数:
name- the parameter name- 返回:
- the parameter value
- 另请参阅:
-
params
Get the parameters with the given name.parameters are contained in the query string or posted form data.
- 参数:
name- the parameter name- 返回:
- the parameter value
- 另请参阅:
-
params
Get all parameters for this request. parameters are contained in the query string or posted form data. -
multipartData
Get the parts of a multipart request, provided the Content-Type is"multipart/form-data", or an exception otherwise.- 返回:
- the multipart data, mapping from name to part(s)
- 抛出:
IOException- if an I/O error occurred during the retrievalNotMultipartRequestException- if this request is not of type"multipart/form-data"- 另请参阅:
-
pathVariable
Get the path variable with the given name, if present.- 参数:
name- the variable name- 返回:
- the variable value
- 抛出:
IllegalArgumentException- if there is no path variable with the given name
-
pathVariables
Get all path variables for this request. -
exchange
RequestContext exchange()Get the request that this request is based on. -
checkNotModified
Check whether the requested resource has been modified given the supplied last-modified timestamp (as determined by the application). If not modified, this method returns a response with corresponding status code and headers, otherwise an empty result.Typical usage:
public ServerResponse myHandleMethod(ServerRequest request) { Instant lastModified = // application-specific calculation return request.checkNotModified(lastModified) .orElseGet(() -> { // further request processing, actually building content return ServerResponse.ok().body(...); }); }This method works with conditional GET/HEAD requests, but also with conditional POST/PUT/DELETE requests.
Note: you can use either this
#checkNotModified(Instant)method; orcheckNotModified(String). If you want to enforce both a strong entity tag and a Last-Modified value, as recommended by the HTTP specification, then you should usecheckNotModified(Instant, String).- 参数:
lastModified- the last-modified timestamp that the application determined for the underlying resource- 返回:
- a corresponding response if the request qualifies as not modified, or an empty result otherwise.
-
checkNotModified
Check whether the requested resource has been modified given the suppliedETag(entity tag), as determined by the application. If not modified, this method returns a response with corresponding status code and headers, otherwise an empty result.Typical usage:
public ServerResponse myHandleMethod(ServerRequest request) { String eTag = // application-specific calculation return request.checkNotModified(eTag) .orElseGet(() -> { // further request processing, actually building content return ServerResponse.ok().body(...); }); }This method works with conditional GET/HEAD requests, but also with conditional POST/PUT/DELETE requests.
Note: you can use either this
checkNotModified(Instant)method; or#checkNotModified(String). If you want to enforce both a strong entity tag and a Last-Modified value, as recommended by the HTTP specification, then you should usecheckNotModified(Instant, String).- 参数:
etag- the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.- 返回:
- a corresponding response if the request qualifies as not modified, or an empty result otherwise.
-
checkNotModified
Check whether the requested resource has been modified given the suppliedETag(entity tag) and last-modified timestamp, as determined by the application. If not modified, this method returns a response with corresponding status code and headers, otherwise an empty result.Typical usage:
public ServerResponse myHandleMethod(ServerRequest request) { Instant lastModified = // application-specific calculation String eTag = // application-specific calculation return request.checkNotModified(lastModified, eTag) .orElseGet(() -> { // further request processing, actually building content return ServerResponse.ok().body(...); }); }This method works with conditional GET/HEAD requests, but also with conditional POST/PUT/DELETE requests.
- 参数:
lastModified- the last-modified timestamp that the application determined for the underlying resourceetag- the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.- 返回:
- a corresponding response if the request qualifies as not modified, or an empty result otherwise.
-
create
Create a newServerRequestbased on the givenRequestContextand message converters.- 参数:
context- the requestmessageReaders- the message readers- 返回:
- the created
ServerRequest
-
from
Create a builder with the status, headers, and cookies of the given request.- 参数:
other- the response to copy the status, headers, and cookies from- 返回:
- the created builder
-
find
-
findRequired
-