Class ServerHttpResponseDecorator
java.lang.Object
org.springframework.http.server.reactive.ServerHttpResponseDecorator
- All Implemented Interfaces:
HttpMessage,ReactiveHttpOutputMessage,ServerHttpResponse
- Direct Known Subclasses:
HttpHeadResponseDecorator
Wraps another
ServerHttpResponse and delegates all methods to it.
Sub-classes can override specific methods selectively.- Since:
- 5.0
- Author:
- Rossen Stoyanchev
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCookie(ResponseCookie cookie) Add the givenResponseCookie.voidbeforeCommit(Supplier<? extends reactor.core.publisher.Mono<Void>> action) Register an action to apply just before the HttpOutputMessage is committed.Return aDataBufferFactorythat can be used to create the body.Return a mutable map with the cookies to send to the server.Return the headers of this message.static <T> TgetNativeResponse(ServerHttpResponse response) Return the native response of the underlying server API, if possible, also unwrappingServerHttpResponseDecoratorif necessary.Return the status code that has been set, or otherwise fall back on the status of the response from the underlying server.Return the status code that has been set, or otherwise fall back on the status of the response from the underlying server.booleanWhether 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).booleansetRawStatusCode(Integer value) Set the HTTP status code to the given value (potentially non-standard and not resolvable through theHttpStatusenum) as an integer.booleansetStatusCode(HttpStatus status) Set the HTTP status code of the response.toString()reactor.core.publisher.Mono<Void>writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) Use the givenPublisherofPublishersto write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after eachPublisher<DataBuffer>.reactor.core.publisher.Mono<Void>writeWith(Publisher<? extends DataBuffer> body) Use the givenPublisherto write the body of the message to the underlying HTTP layer.
-
Constructor Details
-
ServerHttpResponseDecorator
-
-
Method Details
-
getDelegate
-
setStatusCode
Description copied from interface:ServerHttpResponseSet the HTTP status code of the response.- Specified by:
setStatusCodein interfaceServerHttpResponse- Parameters:
status- the HTTP status as anHttpStatusenum value- Returns:
falseif the status code change wasn't processed because the HTTP response is committed,trueif successfully set.
-
getStatusCode
Description copied from interface:ServerHttpResponseReturn 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 benullif the status code value is outside theHttpStatusenum range, or if there is no default value from the underlying server.- Specified by:
getStatusCodein interfaceServerHttpResponse
-
setRawStatusCode
Description copied from interface:ServerHttpResponseSet the HTTP status code to the given value (potentially non-standard and not resolvable through theHttpStatusenum) as an integer.- Specified by:
setRawStatusCodein interfaceServerHttpResponse- Parameters:
value- the status code value- Returns:
falseif the status code change wasn't processed because the HTTP response is committed,trueif successfully set.
-
getRawStatusCode
Description copied from interface:ServerHttpResponseReturn 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 benullif there is no default value from the underlying server.- Specified by:
getRawStatusCodein interfaceServerHttpResponse
-
getHeaders
Description copied from interface:HttpMessageReturn the headers of this message.- Specified by:
getHeadersin interfaceHttpMessage- Returns:
- a corresponding HttpHeaders object (never
null)
-
getCookies
Description copied from interface:ServerHttpResponseReturn a mutable map with the cookies to send to the server.- Specified by:
getCookiesin interfaceServerHttpResponse
-
addCookie
Description copied from interface:ServerHttpResponseAdd the givenResponseCookie.- Specified by:
addCookiein interfaceServerHttpResponse- Parameters:
cookie- the cookie to add
-
bufferFactory
Description copied from interface:ReactiveHttpOutputMessageReturn aDataBufferFactorythat can be used to create the body.- Specified by:
bufferFactoryin interfaceReactiveHttpOutputMessage- Returns:
- a buffer factory
- See Also:
-
beforeCommit
Description copied from interface:ReactiveHttpOutputMessageRegister 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:
beforeCommitin interfaceReactiveHttpOutputMessage- Parameters:
action- the action to apply
-
isCommitted
public boolean isCommitted()Description copied from interface:ReactiveHttpOutputMessageWhether the HttpOutputMessage is committed.- Specified by:
isCommittedin interfaceReactiveHttpOutputMessage
-
writeWith
Description copied from interface:ReactiveHttpOutputMessageUse the givenPublisherto write the body of the message to the underlying HTTP layer.- Specified by:
writeWithin interfaceReactiveHttpOutputMessage- Parameters:
body- the body content publisher- Returns:
- a
Monothat indicates completion or error
-
writeAndFlushWith
public reactor.core.publisher.Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) Description copied from interface:ReactiveHttpOutputMessageUse the givenPublisherofPublishersto write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after eachPublisher<DataBuffer>.- Specified by:
writeAndFlushWithin interfaceReactiveHttpOutputMessage- Parameters:
body- the body content publisher- Returns:
- a
Monothat indicates completion or error
-
setComplete
Description copied from interface:ReactiveHttpOutputMessageIndicate 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:
setCompletein interfaceReactiveHttpOutputMessage- Returns:
- a
Monothat indicates completion or error
-
getNativeResponse
Return the native response of the underlying server API, if possible, also unwrappingServerHttpResponseDecoratorif necessary.- Type Parameters:
T- the expected native response type- Parameters:
response- the response to check- Throws:
IllegalArgumentException- if the native response can't be obtained- Since:
- 5.3.3
-
toString
-