Interface ServerRequest
HandlerFunction.
 Access to headers and body is offered by ServerRequest.Headers and
 body(Class), respectively.- Since:
- 5.2
- Author:
- Arjen Poutsma
- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic interfaceDefines a builder for a request.static interfaceRepresents the headers of the HTTP request.
- 
Method SummaryModifier and TypeMethodDescriptionGet the request attribute value if present.Get a mutable map of request attributes.<T> TExtract the body as an object of the given type.<T> Tbody(ParameterizedTypeReference<T> bodyType) Extract 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.cookies()Get the cookies of this request.static ServerRequestcreate(HttpServletRequest servletRequest, List<HttpMessageConverter<?>> messageReaders) Create a newServerRequestbased on the givenHttpServletRequestand message converters.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.Deprecated.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.default Stringpath()Get the request path.default PathContainerDeprecated.as of 5.3, in favor onrequestPath()default StringpathVariable(String name) Get the path variable with the given name, if present.Get all path variables for this request.Get the authenticated user for the request, if any.Get the remote address to which this request is connected, if available.default RequestPathGet the request path as aPathContainer.Get the servlet request that this request is based on.session()Get the web session for this request.uri()Get the request URI.Get aUriBuilderComponentsfrom the URI associated with thisServerRequest.
- 
Method Details- 
methodHttpMethod method()Get the HTTP method.- Returns:
- the HTTP method as an HttpMethod enum value, or nullif not resolvable (e.g. in case of a non-standard HTTP method)
 
- 
methodNameDeprecated.in favor ofmethod()Get the name of the HTTP method.- Returns:
- the HTTP method as a String
 
- 
uriURI uri()Get the request URI.
- 
uriBuilderUriBuilder uriBuilder()Get aUriBuilderComponentsfrom the URI associated with thisServerRequest.- Returns:
- a URI builder
 
- 
pathGet the request path.
- 
pathContainerDeprecated.as of 5.3, in favor onrequestPath()Get the request path as aPathContainer.
- 
requestPathGet the request path as aPathContainer.- Since:
- 5.3
 
- 
headersServerRequest.Headers headers()Get the headers of this request.
- 
cookiesMultiValueMap<String,Cookie> cookies()Get the cookies of this request.
- 
remoteAddressOptional<InetSocketAddress> remoteAddress()Get the remote address to which this request is connected, if available.
- 
messageConvertersList<HttpMessageConverter<?>> messageConverters()Get the readers used to convert the body of this request.
- 
bodyExtract the body as an object of the given type.- Type Parameters:
- T- the body type
- Parameters:
- bodyType- the type of return value
- Returns:
- the body
- Throws:
- ServletException
- IOException
 
- 
bodyExtract the body as an object of the given type.- Type Parameters:
- T- the body type
- Parameters:
- bodyType- the type of return value
- Returns:
- the body
- Throws:
- ServletException
- IOException
 
- 
attributeGet the request attribute value if present.- Parameters:
- name- the attribute name
- Returns:
- the attribute value
 
- 
attributesGet a mutable map of request attributes.- Returns:
- the request attributes
 
- 
paramGet the first parameter with the given name, if present. Servlet parameters are contained in the query string or posted form data.- Parameters:
- name- the parameter name
- Returns:
- the parameter value
- See Also:
 
- 
paramsMultiValueMap<String,String> params()Get all parameters for this request. Servlet parameters are contained in the query string or posted form data.- See Also:
 
- 
multipartDataGet the parts of a multipart request, provided the Content-Type is"multipart/form-data", or an exception otherwise.- Returns:
- the multipart data, mapping from name to part(s)
- Throws:
- IOException- if an I/O error occurred during the retrieval
- ServletException- if this request is not of type- "multipart/form-data"
- Since:
- 5.3
- See Also:
 
- 
pathVariableGet the path variable with the given name, if present.- Parameters:
- name- the variable name
- Returns:
- the variable value
- Throws:
- IllegalArgumentException- if there is no path variable with the given name
 
- 
pathVariablesGet all path variables for this request.
- 
sessionHttpSession 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.
- 
principalGet the authenticated user for the request, if any.
- 
servletRequestHttpServletRequest servletRequest()Get the servlet request that this request is based on.
- 
checkNotModifiedCheck 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 enforce both a strong entity tag and a Last-Modified value, as recommended by the HTTP specification, then you should usecheckNotModified(Instant, String).- Parameters:
- lastModified- the last-modified timestamp that the application determined for the underlying resource
- Returns:
- a corresponding response if the request qualifies as not modified, or an empty result otherwise.
- Since:
- 5.2.5
 
- 
checkNotModifiedCheck 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 enforce both a strong entity tag and a Last-Modified value, as recommended by the HTTP specification, then you should usecheckNotModified(Instant, String).- Parameters:
- etag- the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.
- Returns:
- a corresponding response if the request qualifies as not modified, or an empty result otherwise.
- Since:
- 5.2.5
 
- 
checkNotModifiedCheck 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. - Parameters:
- lastModified- the last-modified timestamp that the application determined for the underlying resource
- etag- the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.
- Returns:
- a corresponding response if the request qualifies as not modified, or an empty result otherwise.
- Since:
- 5.2.5
 
- 
createstatic ServerRequest create(HttpServletRequest servletRequest, List<HttpMessageConverter<?>> messageReaders) Create a newServerRequestbased on the givenHttpServletRequestand message converters.- Parameters:
- servletRequest- the request
- messageReaders- the message readers
- Returns:
- the created ServerRequest
 
- 
fromCreate a builder with the status, headers, and cookies of the given request.- Parameters:
- other- the response to copy the status, headers, and cookies from
- Returns:
- the created builder
 
 
- 
method()