public interface ServerRequest
HandlerFunction
.
Access to headers and body is offered by ServerRequest.Headers
and
body(BodyExtractor)
, respectively.Modifier and Type | Interface and Description |
---|---|
static interface |
ServerRequest.Headers
Represents the headers of the HTTP request.
|
Modifier and Type | Method and Description |
---|---|
default java.util.Optional<java.lang.Object> |
attribute(java.lang.String name)
Return the request attribute value if present.
|
java.util.Map<java.lang.String,java.lang.Object> |
attributes()
Return a mutable map of request attributes.
|
<T> T |
body(BodyExtractor<T,? super ServerHttpRequest> extractor)
Extract the body with the given
BodyExtractor . |
<T> T |
body(BodyExtractor<T,? super ServerHttpRequest> extractor,
java.util.Map<java.lang.String,java.lang.Object> hints)
Extract the body with the given
BodyExtractor and hints. |
<T> reactor.core.publisher.Flux<T> |
bodyToFlux(java.lang.Class<? extends T> elementClass)
Extract the body to a
Flux . |
<T> reactor.core.publisher.Flux<T> |
bodyToFlux(ParameterizedTypeReference<T> typeReference)
Extract the body to a
Flux . |
<T> reactor.core.publisher.Mono<T> |
bodyToMono(java.lang.Class<? extends T> elementClass)
Extract the body to a
Mono . |
<T> reactor.core.publisher.Mono<T> |
bodyToMono(ParameterizedTypeReference<T> typeReference)
Extract the body to a
Mono . |
MultiValueMap<java.lang.String,HttpCookie> |
cookies()
Return the cookies of this request.
|
static ServerRequest |
create(ServerWebExchange exchange,
java.util.List<HttpMessageReader<?>> messageReaders)
Create a new
ServerRequest based on the given ServerWebExchange and
message readers. |
reactor.core.publisher.Mono<MultiValueMap<java.lang.String,java.lang.String>> |
formData()
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. |
ServerRequest.Headers |
headers()
Return the headers of this request.
|
default HttpMethod |
method()
Return the HTTP method.
|
java.lang.String |
methodName()
Return the name of the HTTP method.
|
reactor.core.publisher.Mono<MultiValueMap<java.lang.String,Part>> |
multipartData()
Return the parts of a multipart request if the Content-Type is
"multipart/form-data" or an empty map otherwise. |
default java.lang.String |
path()
Return the request path.
|
default PathContainer |
pathContainer()
Return the request path as
PathContainer . |
default java.lang.String |
pathVariable(java.lang.String name)
Return the path variable with the given name, if present.
|
java.util.Map<java.lang.String,java.lang.String> |
pathVariables()
Return all path variables for this request.
|
reactor.core.publisher.Mono<? extends java.security.Principal> |
principal()
Return the authenticated user for the request, if any.
|
default java.util.Optional<java.lang.String> |
queryParam(java.lang.String name)
Return the first query parameter with the given name, if present.
|
MultiValueMap<java.lang.String,java.lang.String> |
queryParams()
Return all query parameters for this request.
|
reactor.core.publisher.Mono<WebSession> |
session()
Return the web session for this request.
|
java.net.URI |
uri()
Return the request URI.
|
UriBuilder |
uriBuilder()
Return a
UriBuilderComponents from the URI associated with this
ServerRequest , while also overlaying with values from the headers
"Forwarded" (RFC 7239),
or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if
"Forwarded" is not found. |
@Nullable default HttpMethod method()
null
if not resolvable (e.g. in case of a non-standard HTTP method)java.lang.String methodName()
java.net.URI uri()
UriBuilder uriBuilder()
UriBuilderComponents
from the URI associated with this
ServerRequest
, while also overlaying with values from the headers
"Forwarded" (RFC 7239),
or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if
"Forwarded" is not found.default java.lang.String path()
default PathContainer pathContainer()
PathContainer
.ServerRequest.Headers headers()
MultiValueMap<java.lang.String,HttpCookie> cookies()
<T> T body(BodyExtractor<T,? super ServerHttpRequest> extractor)
BodyExtractor
.T
- the type of the body returnedextractor
- the BodyExtractor
that reads from the requestbody(BodyExtractor, Map)
<T> T body(BodyExtractor<T,? super ServerHttpRequest> extractor, java.util.Map<java.lang.String,java.lang.Object> hints)
BodyExtractor
and hints.T
- the type of the body returnedextractor
- the BodyExtractor
that reads from the requesthints
- the map of hints like Jackson2CodecSupport.JSON_VIEW_HINT
to use to customize body extraction<T> reactor.core.publisher.Mono<T> bodyToMono(java.lang.Class<? extends T> elementClass)
Mono
.T
- the element typeelementClass
- the class of element in the Mono
<T> reactor.core.publisher.Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference)
Mono
.T
- the element typetypeReference
- a type reference describing the expected response request typeT
<T> reactor.core.publisher.Flux<T> bodyToFlux(java.lang.Class<? extends T> elementClass)
Flux
.T
- the element typeelementClass
- the class of element in the Flux
<T> reactor.core.publisher.Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference)
Flux
.T
- the element typetypeReference
- a type reference describing the expected request body typeT
default java.util.Optional<java.lang.Object> attribute(java.lang.String name)
name
- the attribute namejava.util.Map<java.lang.String,java.lang.Object> attributes()
default java.util.Optional<java.lang.String> queryParam(java.lang.String name)
name
- the parameter nameMultiValueMap<java.lang.String,java.lang.String> queryParams()
default java.lang.String pathVariable(java.lang.String name)
name
- the variable namejava.lang.IllegalArgumentException
- if there is no path variable with the given namejava.util.Map<java.lang.String,java.lang.String> pathVariables()
reactor.core.publisher.Mono<WebSession> session()
reactor.core.publisher.Mono<? extends java.security.Principal> principal()
reactor.core.publisher.Mono<MultiValueMap<java.lang.String,java.lang.String>> formData()
"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.
reactor.core.publisher.Mono<MultiValueMap<java.lang.String,Part>> multipartData()
"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.
static ServerRequest create(ServerWebExchange exchange, java.util.List<HttpMessageReader<?>> messageReaders)
ServerRequest
based on the given ServerWebExchange
and
message readers.exchange
- the exchangemessageReaders
- the message readersServerRequest