public static interface ServerResponse.BodyBuilder extends ServerResponse.HeadersBuilder<ServerResponse.BodyBuilder>
Modifier and Type | Method and Description |
---|---|
reactor.core.publisher.Mono<ServerResponse> |
body(BodyInserter<?,? super ServerHttpResponse> inserter)
Set the body of the response to the given
BodyInserter and return it. |
<T,P extends org.reactivestreams.Publisher<T>> |
body(P publisher,
Class<T> elementClass)
Set the body of the response to the given asynchronous
Publisher and return it. |
<T,P extends org.reactivestreams.Publisher<T>> |
body(P publisher,
ParameterizedTypeReference<T> typeReference)
Set the body of the response to the given asynchronous
Publisher and return it. |
ServerResponse.BodyBuilder |
contentLength(long contentLength)
Set the length of the body in bytes, as specified by the
Content-Length header. |
ServerResponse.BodyBuilder |
contentType(MediaType contentType)
Set the media type of the body, as specified by the
Content-Type header. |
ServerResponse.BodyBuilder |
hint(String key,
Object value)
Add a serialization hint like
Jackson2CodecSupport.JSON_VIEW_HINT
to customize how the body will be serialized. |
reactor.core.publisher.Mono<ServerResponse> |
render(String name,
Map<String,?> model)
Render the template with the given
name using the given model . |
reactor.core.publisher.Mono<ServerResponse> |
render(String name,
Object... modelAttributes)
Render the template with the given
name using the given modelAttributes . |
reactor.core.publisher.Mono<ServerResponse> |
syncBody(Object body)
Set the body of the response to the given synchronous
Object and return it. |
allow, allow, build, build, build, cacheControl, eTag, header, headers, lastModified, location, varyBy
ServerResponse.BodyBuilder contentLength(long contentLength)
Content-Length
header.contentLength
- the content lengthHttpHeaders.setContentLength(long)
ServerResponse.BodyBuilder contentType(MediaType contentType)
Content-Type
header.contentType
- the content typeHttpHeaders.setContentType(MediaType)
ServerResponse.BodyBuilder hint(String key, Object value)
Jackson2CodecSupport.JSON_VIEW_HINT
to customize how the body will be serialized.key
- the hint keyvalue
- the hint value<T,P extends org.reactivestreams.Publisher<T>> reactor.core.publisher.Mono<ServerResponse> body(P publisher, Class<T> elementClass)
Publisher
and return it.
This convenience method combines body(BodyInserter)
and
BodyInserters.fromPublisher(Publisher, Class)
.T
- the type of the elements contained in the publisherP
- the type of the Publisher
publisher
- the Publisher
to write to the responseelementClass
- the class of elements contained in the publisher<T,P extends org.reactivestreams.Publisher<T>> reactor.core.publisher.Mono<ServerResponse> body(P publisher, ParameterizedTypeReference<T> typeReference)
Publisher
and return it.
This convenience method combines body(BodyInserter)
and
BodyInserters.fromPublisher(Publisher, Class)
.T
- the type of the elements contained in the publisherP
- the type of the Publisher
publisher
- the Publisher
to write to the responsetypeReference
- a type reference describing the elements contained in the publisherreactor.core.publisher.Mono<ServerResponse> syncBody(Object body)
Object
and return it.
This convenience method combines body(BodyInserter)
and
BodyInserters.fromObject(Object)
.body
- the body of the responseIllegalArgumentException
- if body
is a Publisher
, for which
body(Publisher, Class)
should be used.reactor.core.publisher.Mono<ServerResponse> body(BodyInserter<?,? super ServerHttpResponse> inserter)
BodyInserter
and return it.inserter
- the BodyInserter
that writes to the responsereactor.core.publisher.Mono<ServerResponse> render(String name, Object... modelAttributes)
name
using the given modelAttributes
.
The model attributes are mapped under a
generated name.
Collections
are not added to
the model when using this method because we cannot correctly determine
the true convention name.
name
- the name of the template to be renderedmodelAttributes
- the modelAttributes used to render the templatereactor.core.publisher.Mono<ServerResponse> render(String name, Map<String,?> model)
name
using the given model
.name
- the name of the template to be renderedmodel
- the model used to render the template