Interface ServerRequest
- All Known Implementing Classes:
- MockServerRequest,- ServerRequestWrapper
HandlerFunction.
 Access to headers and body is offered by ServerRequest.Headers and
 body(BodyExtractor), respectively.
- Since:
- 5.0
- Author:
- Arjen Poutsma, Sebastien Deleuze
- 
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.default <T> reactor.core.publisher.Mono<T>Bind to this request and return an instance of the given type.<T> reactor.core.publisher.Mono<T>bind(Class<T> bindType, Consumer<WebDataBinder> dataBinderCustomizer) Bind to this request and return an instance of the given type.<T> Tbody(BodyExtractor<T, ? super ServerHttpRequest> extractor) Extract the body with the givenBodyExtractor.<T> Tbody(BodyExtractor<T, ? super ServerHttpRequest> extractor, Map<String, Object> hints) Extract the body with the givenBodyExtractorand hints.<T> reactor.core.publisher.Flux<T>bodyToFlux(Class<? extends T> elementClass) Extract the body to aFlux.<T> reactor.core.publisher.Flux<T>bodyToFlux(ParameterizedTypeReference<T> typeReference) Extract the body to aFlux.<T> reactor.core.publisher.Mono<T>bodyToMono(Class<? extends T> elementClass) Extract the body to aMono.<T> reactor.core.publisher.Mono<T>bodyToMono(ParameterizedTypeReference<T> typeReference) Extract the body to aMono.default reactor.core.publisher.Mono<ServerResponse>checkNotModified(String etag) Check whether the requested resource has been modified given the suppliedETag(entity tag), as determined by the application.default reactor.core.publisher.Mono<ServerResponse>checkNotModified(Instant lastModified) Check whether the requested resource has been modified given the supplied last-modified timestamp (as determined by the application).default reactor.core.publisher.Mono<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(ServerWebExchange exchange, List<HttpMessageReader<?>> messageReaders) Create a newServerRequestbased on the givenServerWebExchangeand message readers.exchange()Get the web exchange that this request is based on.reactor.core.publisher.Mono<MultiValueMap<String,String>> formData()Get the form data from the body of the request if the Content-Type is"application/x-www-form-urlencoded"or an empty map otherwise.static ServerRequest.Builderfrom(ServerRequest other) Create a builder with the message readers, method name, URI, headers, cookies, and attributes of the given request.headers()Get the headers of this request.Get the local address to which this request is connected, if available.Get the readers used to convert the body of this request.method()Get the HTTP method.Deprecated.reactor.core.publisher.Mono<MultiValueMap<String,Part>> Get the parts of a multipart request if the Content-Type is"multipart/form-data"or an empty map otherwise.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.reactor.core.publisher.Mono<? extends Principal>Get the authenticated user for the request, if any.queryParam(String name) Get the first query parameter with the given name, if present.Get all query parameters for this request.Get the remote address to which this request is connected, if available.default RequestPathGet the request path as aPathContainer.reactor.core.publisher.Mono<WebSession>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.
- 
methodNameDeprecated.as of 6.0, 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.Note: as of 5.1 this method ignores "Forwarded"and"X-Forwarded-*"headers that specify the client-originated address. Consider using theForwardedHeaderFilterto extract and use, or to discard such headers.- 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,HttpCookie> cookies()Get the cookies of this request.
- 
remoteAddressOptional<InetSocketAddress> remoteAddress()Get the remote address to which this request is connected, if available.- Since:
- 5.1
 
- 
localAddressOptional<InetSocketAddress> localAddress()Get the local address to which this request is connected, if available.- Since:
- 5.2.3
 
- 
messageReadersList<HttpMessageReader<?>> messageReaders()Get the readers used to convert the body of this request.- Since:
- 5.1
 
- 
bodyExtract the body with the givenBodyExtractor.- Type Parameters:
- T- the type of the body returned
- Parameters:
- extractor- the- BodyExtractorthat reads from the request
- Returns:
- the extracted body
- See Also:
 
- 
bodyExtract the body with the givenBodyExtractorand hints.- Type Parameters:
- T- the type of the body returned
- Parameters:
- extractor- the- BodyExtractorthat reads from the request
- hints- the map of hints like- Jackson2CodecSupport.JSON_VIEW_HINTto use to customize body extraction
- Returns:
- the extracted body
 
- 
bodyToMonoExtract the body to aMono.- Type Parameters:
- T- the element type
- Parameters:
- elementClass- the class of element in the- Mono
- Returns:
- the body as a mono
 
- 
bodyToMonoExtract the body to aMono.- Type Parameters:
- T- the element type
- Parameters:
- typeReference- a type reference describing the expected response request type
- Returns:
- a mono containing the body of the given type T
 
- 
bodyToFluxExtract the body to aFlux.- Type Parameters:
- T- the element type
- Parameters:
- elementClass- the class of element in the- Flux
- Returns:
- the body as a flux
 
- 
bodyToFluxExtract the body to aFlux.- Type Parameters:
- T- the element type
- Parameters:
- typeReference- a type reference describing the expected request body type
- Returns:
- a flux containing the body of the given type T
 
- 
bindBind to this request and return an instance of the given type.- Type Parameters:
- T- the type to bind to
- Parameters:
- bindType- the type of class to bind this request to
- Returns:
- a mono containing either a constructed and bound instance of
 bindType, or aBindExceptionin case of binding errors
- Since:
- 6.1
 
- 
bind<T> reactor.core.publisher.Mono<T> bind(Class<T> bindType, Consumer<WebDataBinder> dataBinderCustomizer) Bind to this request and return an instance of the given type.- Type Parameters:
- T- the type to bind to
- Parameters:
- bindType- the type of class to bind this request to
- dataBinderCustomizer- used to customize the data binder, for example, set (dis)allowed fields
- Returns:
- a mono containing either a constructed and bound instance of
 bindType, or aBindExceptionin case of binding errors
- Since:
- 6.1
 
- 
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
 
- 
queryParamGet the first query parameter with the given name, if present.- Parameters:
- name- the parameter name
- Returns:
- the parameter value
 
- 
queryParamsMultiValueMap<String,String> queryParams()Get all query parameters for this request.
- 
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.
- 
sessionreactor.core.publisher.Mono<WebSession> session()Get the web session for this request.Always guaranteed to return an instance either matching 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. 
- 
principalreactor.core.publisher.Mono<? extends Principal> principal()Get the authenticated user for the request, if any.
- 
formDatareactor.core.publisher.Mono<MultiValueMap<String,String>> formData()Get 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 MultiValueMapis cached so that this method is safe to call more than once.
- 
multipartDatareactor.core.publisher.Mono<MultiValueMap<String,Part>> multipartData()Get 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 MultiValueMapis cached so that this method is safe to call more than once.
- 
exchangeServerWebExchange exchange()Get the web exchange that this request is based on.Note: Manipulating the exchange directly (instead of using the methods provided on ServerRequestandServerResponse) can lead to irregular results.- Since:
- 5.1
 
- 
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 Mono<ServerResponse> myHandleMethod(ServerRequest request) { Instant lastModified = // application-specific calculation return request.checkNotModified(lastModified) .switchIfEmpty(Mono.defer(() -> { // 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).- 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 Mono<ServerResponse> myHandleMethod(ServerRequest request) { String eTag = // application-specific calculation return request.checkNotModified(eTag) .switchIfEmpty(Mono.defer(() -> { // 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).- Parameters:
- etag- the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary. Use an empty string- ""for no value.
- Returns:
- a corresponding response if the request qualifies as not modified, or an empty result otherwise
- Since:
- 5.2.5
 
- 
checkNotModifieddefault reactor.core.publisher.Mono<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.If not modified, this method returns a response with corresponding status code and headers, otherwise an empty result. Typical usage: public Mono<ServerResponse> myHandleMethod(ServerRequest request) { Instant lastModified = // application-specific calculation String eTag = // application-specific calculation return request.checkNotModified(lastModified, eTag) .switchIfEmpty(Mono.defer(() -> { // 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. Use an empty string- ""for no value.
- Returns:
- a corresponding response if the request qualifies as not modified, or an empty result otherwise.
- Since:
- 5.2.5
 
- 
createCreate a newServerRequestbased on the givenServerWebExchangeand message readers.- Parameters:
- exchange- the exchange
- messageReaders- the message readers
- Returns:
- the created ServerRequest
 
- 
fromCreate a builder with the message readers, method name, URI, headers, cookies, and attributes of the given request.- Parameters:
- other- the request to copy the message readers, method name, URI, headers, and attributes from
- Returns:
- the created builder
- Since:
- 5.1
 
 
- 
method()