Class AbstractServerHttpResponse
- All Implemented Interfaces:
HttpMessage
,ReactiveHttpOutputMessage
,ServerHttpResponse
- Direct Known Subclasses:
AbstractListenerServerHttpResponse
,MockServerHttpResponse
ServerHttpResponse
implementations.- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze, Brian Clozel
-
Constructor Summary
ConstructorDescriptionAbstractServerHttpResponse
(DataBufferFactory dataBufferFactory) AbstractServerHttpResponse
(DataBufferFactory dataBufferFactory, HttpHeaders headers) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCookie
(ResponseCookie cookie) Add the givenResponseCookie
.protected abstract void
Add cookies fromgetHeaders()
to the underlying response.protected abstract void
Invoked when the response is getting committed allowing subclasses to make apply header values to the underlying response.protected abstract void
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.final DataBufferFactory
Return aDataBufferFactory
that can be used to create the body.protected reactor.core.publisher.Mono<Void>
doCommit()
A variant ofdoCommit(Supplier)
for a response without a body.protected reactor.core.publisher.Mono<Void>
ApplybeforeCommit
actions, apply the response status and headers/cookies, and write the response body.Return a mutable map with the cookies to send to the server.Return the headers of this message.abstract <T> T
Return the underlying server response.Return the status code that has been set, or otherwise fall back on the status of the response from the underlying server.boolean
Whether the HttpOutputMessage is committed.reactor.core.publisher.Mono<Void>
Indicate that message handling is complete, allowing for any cleanup or end-of-processing tasks to be performed such as applying header changes made viaHttpMessage.getHeaders()
to the underlying HTTP message (if not applied already).boolean
setRawStatusCode
(Integer statusCode) Set the HTTP status code to the given value as an integer.boolean
setStatusCode
(HttpStatusCode status) Set the HTTP status code of the response.protected void
touchDataBuffer
(DataBuffer buffer) Allow subclasses to associate a hint with the data buffer if it is a pooled buffer and supports leak tracking.final reactor.core.publisher.Mono<Void>
writeAndFlushWith
(Publisher<? extends Publisher<? extends DataBuffer>> body) Use the givenPublisher
ofPublishers
to write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after eachPublisher<DataBuffer>
.protected abstract reactor.core.publisher.Mono<Void>
writeAndFlushWithInternal
(Publisher<? extends Publisher<? extends DataBuffer>> body) Write to the underlying the response, and flush after eachPublisher<DataBuffer>
.final reactor.core.publisher.Mono<Void>
writeWith
(Publisher<? extends DataBuffer> body) Use the givenPublisher
to write the body of the message to the underlying HTTP layer.protected abstract reactor.core.publisher.Mono<Void>
writeWithInternal
(Publisher<? extends DataBuffer> body) Write to the underlying the response.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.http.server.reactive.ServerHttpResponse
getRawStatusCode
-
Constructor Details
-
AbstractServerHttpResponse
-
AbstractServerHttpResponse
-
-
Method Details
-
bufferFactory
Description copied from interface:ReactiveHttpOutputMessage
Return aDataBufferFactory
that can be used to create the body.- Specified by:
bufferFactory
in interfaceReactiveHttpOutputMessage
- Returns:
- a buffer factory
- See Also:
-
setStatusCode
Description copied from interface:ServerHttpResponse
Set the HTTP status code of the response.- Specified by:
setStatusCode
in interfaceServerHttpResponse
- Parameters:
status
- the HTTP status as anHttpStatusCode
value- Returns:
false
if the status code change wasn't processed because the HTTP response is committed,true
if successfully set.
-
getStatusCode
Description copied from interface:ServerHttpResponse
Return the status code that has been set, or otherwise fall back on the status of the response from the underlying server. The return value may benull
if there is no default value from the underlying server.- Specified by:
getStatusCode
in interfaceServerHttpResponse
-
setRawStatusCode
Description copied from interface:ServerHttpResponse
Set the HTTP status code to the given value as an integer.- Specified by:
setRawStatusCode
in interfaceServerHttpResponse
- Parameters:
statusCode
- the status code value- Returns:
false
if the status code change wasn't processed because the HTTP response is committed,true
if successfully set.
-
getHeaders
Description copied from interface:HttpMessage
Return the headers of this message.- Specified by:
getHeaders
in interfaceHttpMessage
- Returns:
- a corresponding HttpHeaders object (never
null
)
-
getCookies
Description copied from interface:ServerHttpResponse
Return a mutable map with the cookies to send to the server.- Specified by:
getCookies
in interfaceServerHttpResponse
-
addCookie
Description copied from interface:ServerHttpResponse
Add the givenResponseCookie
.- Specified by:
addCookie
in interfaceServerHttpResponse
- Parameters:
cookie
- the cookie to add
-
getNativeResponse
public abstract <T> T getNativeResponse()Return the underlying server response.Note: This is exposed mainly for internal framework use such as WebSocket upgrades in the spring-webflux module.
-
beforeCommit
Description copied from interface:ReactiveHttpOutputMessage
Register an action to apply just before the HttpOutputMessage is committed.Note: the supplied action must be properly deferred, e.g. via
Mono.defer(java.util.function.Supplier<? extends reactor.core.publisher.Mono<? extends T>>)
orMono.fromRunnable(java.lang.Runnable)
, to ensure it's executed in the right order, relative to other actions.- Specified by:
beforeCommit
in interfaceReactiveHttpOutputMessage
- Parameters:
action
- the action to apply
-
isCommitted
public boolean isCommitted()Description copied from interface:ReactiveHttpOutputMessage
Whether the HttpOutputMessage is committed.- Specified by:
isCommitted
in interfaceReactiveHttpOutputMessage
-
writeWith
Description copied from interface:ReactiveHttpOutputMessage
Use the givenPublisher
to write the body of the message to the underlying HTTP layer.- Specified by:
writeWith
in interfaceReactiveHttpOutputMessage
- Parameters:
body
- the body content publisher- Returns:
- a
Mono
that indicates completion or error
-
writeAndFlushWith
public final reactor.core.publisher.Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) Description copied from interface:ReactiveHttpOutputMessage
Use the givenPublisher
ofPublishers
to write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after eachPublisher<DataBuffer>
.- Specified by:
writeAndFlushWith
in interfaceReactiveHttpOutputMessage
- Parameters:
body
- the body content publisher- Returns:
- a
Mono
that indicates completion or error
-
setComplete
Description copied from interface:ReactiveHttpOutputMessage
Indicate that message handling is complete, allowing for any cleanup or end-of-processing tasks to be performed such as applying header changes made viaHttpMessage.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.
- Specified by:
setComplete
in interfaceReactiveHttpOutputMessage
- Returns:
- a
Mono
that indicates completion or error
-
doCommit
A variant ofdoCommit(Supplier)
for a response without a body.- Returns:
- a completion publisher
-
doCommit
protected reactor.core.publisher.Mono<Void> doCommit(@Nullable Supplier<? extends reactor.core.publisher.Mono<Void>> writeAction) ApplybeforeCommit
actions, apply the response status and headers/cookies, and write the response body.- Parameters:
writeAction
- the action to write the response body (may benull
)- Returns:
- a completion publisher
-
writeWithInternal
protected abstract reactor.core.publisher.Mono<Void> writeWithInternal(Publisher<? extends DataBuffer> body) Write to the underlying the response.- Parameters:
body
- the publisher to write with
-
writeAndFlushWithInternal
protected abstract reactor.core.publisher.Mono<Void> writeAndFlushWithInternal(Publisher<? extends Publisher<? extends DataBuffer>> body) Write to the underlying the response, and flush after eachPublisher<DataBuffer>
.- Parameters:
body
- the publisher to write and flush with
-
applyStatusCode
protected abstract void applyStatusCode()Write the status code to the underlying response. This method is called once only. -
applyHeaders
protected abstract void applyHeaders()Invoked when the response is getting committed allowing subclasses to make apply header values to the underlying response.Note that some subclasses use an
HttpHeaders
instance that wraps an adapter to the native response headers such that changes are propagated to the underlying response on the go. That means this callback might not be used other than for specialized updates such as setting the contentType or characterEncoding fields in a Servlet response. -
applyCookies
protected abstract void applyCookies()Add cookies fromgetHeaders()
to the underlying response. This method is called once only. -
touchDataBuffer
Allow subclasses to associate a hint with the data buffer if it is a pooled buffer and supports leak tracking.- Parameters:
buffer
- the buffer to attach a hint to- Since:
- 5.3.2
-