public abstract class AbstractServerHttpResponse extends Object implements ServerHttpResponse
ServerHttpResponse
implementations.Constructor and Description |
---|
AbstractServerHttpResponse(DataBufferFactory dataBufferFactory) |
AbstractServerHttpResponse(DataBufferFactory dataBufferFactory,
HttpHeaders headers) |
Modifier and Type | Method and Description |
---|---|
void |
addCookie(ResponseCookie cookie)
Add the given
ResponseCookie . |
protected abstract void |
applyCookies()
Add cookies from
getHeaders() to the underlying response. |
protected abstract void |
applyHeaders()
Apply header changes from
getHeaders() to the underlying response. |
protected abstract void |
applyStatusCode()
Write the status code to the underlying response.
|
void |
beforeCommit(Supplier<? extends reactor.core.publisher.Mono<Void>> action)
Register an action to apply just before the HttpOutputMessage is committed.
|
DataBufferFactory |
bufferFactory()
Return a
DataBufferFactory that can be used to create the body. |
protected reactor.core.publisher.Mono<Void> |
doCommit()
A variant of
doCommit(Supplier) for a response without no body. |
protected reactor.core.publisher.Mono<Void> |
doCommit(Supplier<? extends reactor.core.publisher.Mono<Void>> writeAction)
Apply
beforeCommit actions, apply the
response status and headers/cookies, and write the response body. |
MultiValueMap<String,ResponseCookie> |
getCookies()
Return a mutable map with the cookies to send to the server.
|
HttpHeaders |
getHeaders()
Return the headers of this message.
|
abstract <T> T |
getNativeResponse()
Return the underlying server response.
|
HttpStatus |
getStatusCode()
Return the status code set via
ServerHttpResponse.setStatusCode(org.springframework.http.HttpStatus) , or if the status
has not been set, return the default status code from the underlying
server response. |
Integer |
getStatusCodeValue()
Return the HTTP status code of the response.
|
boolean |
isCommitted()
Whether the HttpOutputMessage is committed.
|
reactor.core.publisher.Mono<Void> |
setComplete()
Indicate that message handling is complete, allowing for any cleanup or
end-of-processing tasks to be performed such as applying header changes
made via
HttpMessage.getHeaders() to the underlying HTTP message (if not
applied already). |
boolean |
setStatusCode(HttpStatus status)
Set the HTTP status code of the response.
|
void |
setStatusCodeValue(Integer statusCode)
Set the HTTP status code of the response.
|
reactor.core.publisher.Mono<Void> |
writeAndFlushWith(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
Use the given
Publisher of Publishers to write the body
of the HttpOutputMessage to the underlying HTTP layer, flushing after
each Publisher<DataBuffer> . |
protected abstract reactor.core.publisher.Mono<Void> |
writeAndFlushWithInternal(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
Write to the underlying the response, and flush after each
Publisher<DataBuffer> . |
reactor.core.publisher.Mono<Void> |
writeWith(org.reactivestreams.Publisher<? extends DataBuffer> body)
Use the given
Publisher to write the body of the message to the
underlying HTTP layer. |
protected abstract reactor.core.publisher.Mono<Void> |
writeWithInternal(org.reactivestreams.Publisher<? extends DataBuffer> body)
Write to the underlying the response.
|
protected final Log logger
public AbstractServerHttpResponse(DataBufferFactory dataBufferFactory)
public AbstractServerHttpResponse(DataBufferFactory dataBufferFactory, HttpHeaders headers)
public final DataBufferFactory bufferFactory()
ReactiveHttpOutputMessage
DataBufferFactory
that can be used to create the body.bufferFactory
in interface ReactiveHttpOutputMessage
ReactiveHttpOutputMessage.writeWith(Publisher)
public boolean setStatusCode(@Nullable HttpStatus status)
ServerHttpResponse
setStatusCode
in interface ServerHttpResponse
status
- the HTTP status as an HttpStatus
enum valuefalse
if the status code has not been set because the
HTTP response is already committed, true
if successfully set.@Nullable public HttpStatus getStatusCode()
ServerHttpResponse
ServerHttpResponse.setStatusCode(org.springframework.http.HttpStatus)
, or if the status
has not been set, return the default status code from the underlying
server response. The return value may be null
if the status code
value is outside the HttpStatus
enum range, or if the underlying
server response does not have a default value.getStatusCode
in interface ServerHttpResponse
public void setStatusCodeValue(@Nullable Integer statusCode)
statusCode
- the HTTP status as an integer value@Nullable public Integer getStatusCodeValue()
public HttpHeaders getHeaders()
HttpMessage
getHeaders
in interface HttpMessage
null
)public MultiValueMap<String,ResponseCookie> getCookies()
ServerHttpResponse
getCookies
in interface ServerHttpResponse
public void addCookie(ResponseCookie cookie)
ServerHttpResponse
ResponseCookie
.addCookie
in interface ServerHttpResponse
cookie
- the cookie to addpublic abstract <T> T getNativeResponse()
Note: This is exposed mainly for internal framework use such as WebSocket upgrades in the spring-webflux module.
public void beforeCommit(Supplier<? extends reactor.core.publisher.Mono<Void>> action)
ReactiveHttpOutputMessage
Note: the supplied action must be properly deferred,
e.g. via Mono.defer(java.util.function.Supplier<? extends reactor.core.publisher.Mono<? extends T>>)
or Mono.fromRunnable(java.lang.Runnable)
, to ensure it's
executed in the right order, relative to other actions.
beforeCommit
in interface ReactiveHttpOutputMessage
action
- the action to applypublic boolean isCommitted()
ReactiveHttpOutputMessage
isCommitted
in interface ReactiveHttpOutputMessage
public final reactor.core.publisher.Mono<Void> writeWith(org.reactivestreams.Publisher<? extends DataBuffer> body)
ReactiveHttpOutputMessage
Publisher
to write the body of the message to the
underlying HTTP layer.writeWith
in interface ReactiveHttpOutputMessage
body
- the body content publisherMono
that indicates completion or errorpublic final reactor.core.publisher.Mono<Void> writeAndFlushWith(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
ReactiveHttpOutputMessage
Publisher
of Publishers
to write the body
of the HttpOutputMessage to the underlying HTTP layer, flushing after
each Publisher<DataBuffer>
.writeAndFlushWith
in interface ReactiveHttpOutputMessage
body
- the body content publisherMono
that indicates completion or errorpublic reactor.core.publisher.Mono<Void> setComplete()
ReactiveHttpOutputMessage
HttpMessage.getHeaders()
to the underlying HTTP message (if not
applied already).
This method should be automatically invoked at the end of message processing so typically applications should not have to invoke it. If invoked multiple times it should have no side effects.
setComplete
in interface ReactiveHttpOutputMessage
Mono
that indicates completion or errorprotected reactor.core.publisher.Mono<Void> doCommit()
doCommit(Supplier)
for a response without no body.protected reactor.core.publisher.Mono<Void> doCommit(@Nullable Supplier<? extends reactor.core.publisher.Mono<Void>> writeAction)
beforeCommit
actions, apply the
response status and headers/cookies, and write the response body.writeAction
- the action to write the response body (may be null
)protected abstract reactor.core.publisher.Mono<Void> writeWithInternal(org.reactivestreams.Publisher<? extends DataBuffer> body)
body
- the publisher to write withprotected abstract reactor.core.publisher.Mono<Void> writeAndFlushWithInternal(org.reactivestreams.Publisher<? extends org.reactivestreams.Publisher<? extends DataBuffer>> body)
Publisher<DataBuffer>
.body
- the publisher to write and flush withprotected abstract void applyStatusCode()
protected abstract void applyHeaders()
getHeaders()
to the underlying response.
This method is called once only.protected abstract void applyCookies()
getHeaders()
to the underlying response.
This method is called once only.