HandlerFunction.
Access to headers and body is offered by Headers and
body(Class), respectively.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | ServerRequest.
Defines a builder for a request. |
| public static interface | ServerRequest.
Represents the headers of the HTTP request. |
| Modifier and Type | Method and Description |
|---|---|
| public default Optional | |
| public Map | |
| public default < the type to bind to T> T | |
| public < the type to bind to T> T | Returns: a constructed and bound instance ofbindTypethe type of class to bind this request to bindType, Consumer<WebDataBinder> used to customize the data binder, e.g. set
(dis)allowed fields dataBinderCustomizer)Bind to this request and return an instance of the given type. |
| public < the body type T> T | |
| public < the body type T> T | Returns: the bodythe type of return value bodyType)Extract the body as an object of the given type. |
| public default Optional | Returns: a corresponding response if the request qualifies as not modified, or an empty result otherwise.the last-modified timestamp that the
application determined for the underlying resource lastModified)Check whether the requested resource has been modified given the supplied last-modified timestamp (as determined by the application). |
| public default Optional | Returns: a corresponding response if the request qualifies as not modified, or an empty result otherwise.the entity tag that the application determined
for the underlying resource. This parameter will be padded
with quotes (") if necessary. etag)Check whether the requested resource has been modified given the
supplied |
| public default Optional | Returns: a corresponding response if the request qualifies as not modified, or an empty result otherwise.the last-modified timestamp that the
application determined for the underlying resource lastModified, String the entity tag that the application determined
for the underlying resource. This parameter will be padded
with quotes (") if necessary. etag)Check whether the requested resource has been modified given the
supplied |
| public MultiValueMap | |
| public static ServerRequest | Returns: the createdServerRequestthe request servletRequest, List<HttpMessageConverter<?>> the message readers messageReaders)Create a new |
| public static ServerRequest. | Returns: the created builderthe response to copy the status, headers, and cookies from other)Create a builder with the status, headers, and cookies of the given request. |
| public ServerRequest. | |
| public List | |
| public HttpMethod | Returns: the HTTP method as an HttpMethod enum value, ornull
if not resolvable (e.g. in case of a non-standard HTTP method)Get the HTTP method. |
| public String | Returns: the HTTP method as a String
Deprecated
in favor of
method()
Get the name of the HTTP method. |
| public MultiValueMap | Returns: the multipart data, mapping from name to part(s)Get the parts of a multipart request, provided the Content-Type is
|
| public default Optional | |
| public MultiValueMap | |
| public default String | |
| public default PathContainer | pathContainer()
Deprecated
as of 5.3, in favor on
requestPath()
Get the request path as a |
| public default String | Returns: the variable valuethe variable name name)Get the path variable with the given name, if present. |
| public Map | |
| public Optional | |
| public Optional | |
| public default RequestPath | |
| public HttpServletRequest | |
| public HttpSession | |
| public URI | |
| public UriBuilder | Returns: a URI builderGet a |
| attribute | back to summary |
|---|---|
| public default Optional Get the request attribute value if present. | |
| attributes | back to summary |
|---|---|
| public Map Get a mutable map of request attributes. | |
| bind | back to summary |
|---|---|
| public default <T> T bind(Class<T> bindType) throws BindException Bind to this request and return an instance of the given type.
| |
| bind | back to summary |
|---|---|
| public <T> T bind(Class<T> bindType, Consumer<WebDataBinder> dataBinderCustomizer) throws BindException Bind to this request and return an instance of the given type.
| |
| body | back to summary |
|---|---|
| public <T> T body(Class<T> bodyType) throws ServletException, IOException Extract the body as an object of the given type.
| |
| body | back to summary |
|---|---|
| public <T> T body(ParameterizedTypeReference<T> bodyType) throws ServletException, IOException Extract the body as an object of the given type.
| |
| checkNotModified | back to summary |
|---|---|
| public default Optional 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 | back to summary |
|---|---|
| public default Optional Check whether the requested resource has been modified given the
supplied 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 | back to summary |
|---|---|
| public default Optional Check whether the requested resource has been modified given the
supplied 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.
| |
| cookies | back to summary |
|---|---|
| public MultiValueMap Get the cookies of this request. | |
| create | back to summary |
|---|---|
| public static ServerRequest create(HttpServletRequest servletRequest, List<HttpMessageConverter<?>> messageReaders) Create a new
| |
| from | back to summary |
|---|---|
| public static ServerRequest. Create a builder with the status, headers, and cookies of the given request.
| |
| headers | back to summary |
|---|---|
| public ServerRequest. Get the headers of this request. | |
| messageConverters | back to summary |
|---|---|
| public List Get the readers used to convert the body of this request. | |
| method | back to summary |
|---|---|
| public HttpMethod method() Get the HTTP method.
| |
| methodName | back to summary |
|---|---|
| public String methodName()
Deprecated in favor of Get the name of the HTTP method.
| |
| multipartData | back to summary |
|---|---|
| public MultiValueMap Get the parts of a multipart request, provided the Content-Type is
| |
| param | back to summary |
|---|---|
| public default Optional Get the first parameter with the given name, if present. Servlet parameters are contained in the query string or posted form data.
| |
| params | back to summary |
|---|---|
| public MultiValueMap Get all parameters for this request. Servlet parameters are contained in the query string or posted form data.
| |
| path | back to summary |
|---|---|
| public default String path() Get the request path. | |
| pathContainer | back to summary |
|---|---|
| public default PathContainer pathContainer()
Deprecated as of 5.3, in favor on Get the request path as a
| |
| pathVariable | back to summary |
|---|---|
| public default String pathVariable(String name) Get the path variable with the given name, if present.
| |
| pathVariables | back to summary |
|---|---|
| public Map Get all path variables for this request. | |
| principal | back to summary |
|---|---|
| public Optional Get the authenticated user for the request, if any. | |
| remoteAddress | back to summary |
|---|---|
| public Optional Get the remote address to which this request is connected, if available. | |
| requestPath | back to summary |
|---|---|
| public default RequestPath requestPath() Get the request path as a
| |
| servletRequest | back to summary |
|---|---|
| public HttpServletRequest servletRequest() Get the servlet request that this request is based on. | |
| session | back to summary |
|---|---|
| public HttpSession session() Get the web session for this 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. | |
| uri | back to summary |
|---|---|
| public URI uri() Get the request URI. | |
| uriBuilder | back to summary |
|---|---|
| public UriBuilder uriBuilder() Get a
| |
| Modifier and Type | Method and Description |
|---|---|
| public ServerRequest. | |
| public ServerRequest. | Returns: this buildera function that consumes the attributes map attributesConsumer)Manipulate this request's attributes with the given consumer. |
| public ServerRequest. | |
| public ServerRequest. | |
| public ServerRequest | |
| public ServerRequest. | |
| public ServerRequest. | Returns: this buildera function that consumes the cookies map cookiesConsumer)Manipulate this request's cookies with the given consumer. |
| public ServerRequest. | |
| public ServerRequest. | Returns: this buildera function that consumes the headersConsumer)HttpHeadersManipulate this request's headers with the given consumer. |
| public ServerRequest. | |
| public ServerRequest. | |
| public ServerRequest. | Returns: this buildera function that consumes the parameters map paramsConsumer)Manipulate this request's parameters with the given consumer. |
| public ServerRequest. | Returns: this builderthe remote address remoteAddress)Set the remote address of the request. |
| public ServerRequest. |
| attribute | back to summary |
|---|---|
| public ServerRequest. Add an attribute with the given name and value.
| |
| attributes | back to summary |
|---|---|
| public ServerRequest. Manipulate this request's attributes with the given consumer. The map provided to the consumer is "live", so that the consumer can be used
to overwrite existing attributes,
remove attributes, or use any of the other
| |
| body | back to summary |
|---|---|
| public ServerRequest. Set the body of the request. Calling this methods will release the existing body of the builder.
| |
| body | back to summary |
|---|---|
| public ServerRequest. Set the body of the request to the UTF-8 encoded bytes of the given string. Calling this methods will release the existing body of the builder.
| |
| build | back to summary |
|---|---|
| public ServerRequest build() Build the request.
| |
| cookie | back to summary |
|---|---|
| public ServerRequest. Add a cookie with the given name and value(s).
| |
| cookies | back to summary |
|---|---|
| public ServerRequest. Manipulate this request's cookies with the given consumer. The map provided to the consumer is "live", so that the consumer can be used to
overwrite existing cookies,
remove cookies, or use any of the other
| |
| header | back to summary |
|---|---|
| public ServerRequest. Add the given header value(s) under the given name.
| |
| headers | back to summary |
|---|---|
| public ServerRequest. Manipulate this request's headers with the given consumer. The headers provided to the consumer are "live", so that the consumer can be used to
overwrite existing header values,
remove values, or use any of the other
| |
| method | back to summary |
|---|---|
| public ServerRequest. Set the method of the request.
| |
| param | back to summary |
|---|---|
| public ServerRequest. Add a parameter with the given name and value.
| |
| params | back to summary |
|---|---|
| public ServerRequest. Manipulate this request's parameters with the given consumer. The map provided to the consumer is "live", so that the consumer can be used to
overwrite existing cookies,
remove cookies, or use any of the other
| |
| remoteAddress | back to summary |
|---|---|
| public ServerRequest. Set the remote address of the request.
| |
| uri | back to summary |
|---|---|
| public ServerRequest. Set the URI of the request.
| |
ServerRequest#headers()
| Modifier and Type | Method and Description |
|---|---|
| public List | |
| public List | |
| public List | |
| public HttpHeaders | |
| public OptionalLong | |
| public Optional | |
| public default String | firstHeader(String
the header name headerName)Get the first header value, if any, for the header for the given name. |
| public List | |
| public InetSocketAddress | |
| public List |
| accept | back to summary |
|---|---|
| public List Get the list of acceptable media types, as specified by the Returns an empty list if the acceptable media types are unspecified. | |
| acceptCharset | back to summary |
|---|---|
| public List Get the list of acceptable charsets, as specified by the
| |
| acceptLanguage | back to summary |
|---|---|
| public List Get the list of acceptable languages, as specified by the
| |
| asHttpHeaders | back to summary |
|---|---|
| public HttpHeaders asHttpHeaders() Get the headers as an instance of | |
| contentLength | back to summary |
|---|---|
| public OptionalLong contentLength() Get the length of the body in bytes, as specified by the
| |
| contentType | back to summary |
|---|---|
| public Optional Get the media type of the body, as specified by the
| |
| firstHeader | back to summary |
|---|---|
| public default String firstHeader(String headerName) Get the first header value, if any, for the header for the given name. Returns | |
| header | back to summary |
|---|---|
| public List Get the header value(s), if any, for the header of the given name. Returns an empty list if no header values are found.
| |
| host | back to summary |
|---|---|
| public InetSocketAddress host() Get the value of the If the header value does not contain a port, the
port in the returned address will
be
| |
| range | back to summary |
|---|---|
| public List Get the value of the Returns an empty list when the range is unknown. | |