Package org.springframework.http.server.reactive

# Class ServerHttpResponseDecorator

java.lang.Object
org.springframework.http.server.reactive.ServerHttpResponseDecorator

All Implemented Interfaces:
  `HttpMessage`, `ReactiveHttpOutputMessage`, `ServerHttpResponse`

Direct Known Subclasses:
  `HttpHeadResponseDecorator`

public class ServerHttpResponseDecorator extends Object implements ServerHttpResponse
Wraps another `ServerHttpResponse` and delegates all methods to it. Subclasses can override specific methods selectively.

Since:
  5.0
Author:
  Rossen Stoyanchev

## Constructor Summary

Constructors
Constructor
Description
`ServerHttpResponseDecorator(ServerHttpResponse delegate)`

## Method Summary

Modifier and Type
Method
Description
`void`
`addCookie(ResponseCookie cookie)`
Add the given `ResponseCookie`.
`void`
`beforeCommit(Supplier<? extends reactor.core.publisher.Mono<Void>> action)`
Register an action to apply just before the HttpOutputMessage is committed.
`org.springframework.core.io.buffer.DataBufferFactory`
`bufferFactory()`
Return a `DataBufferFactory` that can be used to create the body.
`org.springframework.util.MultiValueMap<String,ResponseCookie>`
`getCookies()`
Return a mutable map with the cookies to send to the server.
`ServerHttpResponse`
`getDelegate()`
`HttpHeaders`
`getHeaders()`
Return the headers of this message.
`static <T> T`
`getNativeResponse(ServerHttpResponse response)`
Return the native response of the underlying server API, if possible, also unwrapping `ServerHttpResponseDecorator` if necessary.
`Integer`
`getRawStatusCode()`
Deprecated.
`HttpStatusCode`
`getStatusCode()`
Return the status code that has been set, or otherwise fall back on the status of the response from the underlying server.
`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`
`setRawStatusCode(Integer value)`
Set the HTTP status code to the given value as an integer.
`boolean`
`setStatusCode(HttpStatusCode status)`
Set the HTTP status code of the response.
`String`
`toString()`
`reactor.core.publisher.Mono<Void>`
`writeAndFlushWith(Publisher<? extends Publisher<? extends org.springframework.core.io.buffer.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>`.
`reactor.core.publisher.Mono<Void>`
`writeWith(Publisher<? extends org.springframework.core.io.buffer.DataBuffer> body)`
Use the given `Publisher` to write the body of the message to the underlying HTTP layer.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### ServerHttpResponseDecorator

public ServerHttpResponseDecorator(ServerHttpResponse delegate)

## Method Details

### getDelegate

public ServerHttpResponse getDelegate()

### setStatusCode

public boolean setStatusCode(@Nullable HttpStatusCode status)
Description copied from interface: `ServerHttpResponse`
Set the HTTP status code of the response.

Specified by:
  `setStatusCode` in interface `ServerHttpResponse`
Parameters:
  `status` - the HTTP status as an `HttpStatusCode` value
Returns:
  `false` if the status code change wasn't processed because the HTTP response is committed, `true` if successfully set.

### getStatusCode

@Nullable public HttpStatusCode 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 be `null` if there is no default value from the underlying server.

Specified by:
  `getStatusCode` in interface `ServerHttpResponse`

### setRawStatusCode

public boolean setRawStatusCode(@Nullable Integer value)
Description copied from interface: `ServerHttpResponse`
Set the HTTP status code to the given value as an integer.

Specified by:
  `setRawStatusCode` in interface `ServerHttpResponse`
Parameters:
  `value` - the status code value
Returns:
  `false` if the status code change wasn't processed because the HTTP response is committed, `true` if successfully set.

### getRawStatusCode

@Nullable @Deprecated public Integer getRawStatusCode()
Deprecated.
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 be `null` if there is no default value from the underlying server.

Specified by:
  `getRawStatusCode` in interface `ServerHttpResponse`

### getHeaders

public HttpHeaders getHeaders()
Description copied from interface: `HttpMessage`
Return the headers of this message.

Specified by:
  `getHeaders` in interface `HttpMessage`
Returns:
  a corresponding HttpHeaders object (never `null`)

### getCookies

public org.springframework.util.MultiValueMap<String,ResponseCookie> getCookies()
Description copied from interface: `ServerHttpResponse`
Return a mutable map with the cookies to send to the server.

Specified by:
  `getCookies` in interface `ServerHttpResponse`

### addCookie

public void addCookie(ResponseCookie cookie)
Description copied from interface: `ServerHttpResponse`
Add the given `ResponseCookie`.

Specified by:
  `addCookie` in interface `ServerHttpResponse`
Parameters:
  `cookie` - the cookie to add

### bufferFactory

public org.springframework.core.io.buffer.DataBufferFactory bufferFactory()
Description copied from interface: `ReactiveHttpOutputMessage`
Return a `DataBufferFactory` that can be used to create the body.

Specified by:
  `bufferFactory` in interface `ReactiveHttpOutputMessage`
Returns:
  a buffer factory
See Also:
  - `ReactiveHttpOutputMessage.writeWith(Publisher)`

### beforeCommit

public void beforeCommit(Supplier<? extends reactor.core.publisher.Mono<Void>> action)
Description copied from interface: `ReactiveHttpOutputMessage`
Register an action to apply just before the HttpOutputMessage is committed.

Note: the supplied action must be properly deferred, for example, 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.

Specified by:
  `beforeCommit` in interface `ReactiveHttpOutputMessage`
Parameters:
  `action` - the action to apply

### isCommitted

public boolean isCommitted()
Description copied from interface: `ReactiveHttpOutputMessage`
Whether the HttpOutputMessage is committed.

Specified by:
  `isCommitted` in interface `ReactiveHttpOutputMessage`

### writeWith

public reactor.core.publisher.Mono<Void> writeWith(Publisher<? extends org.springframework.core.io.buffer.DataBuffer> body)
Description copied from interface: `ReactiveHttpOutputMessage`
Use the given `Publisher` to write the body of the message to the underlying HTTP layer.

Specified by:
  `writeWith` in interface `ReactiveHttpOutputMessage`
Parameters:
  `body` - the body content publisher
Returns:
  a `Mono` that indicates completion or error

### writeAndFlushWith

public reactor.core.publisher.Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends org.springframework.core.io.buffer.DataBuffer>> body)
Description copied from interface: `ReactiveHttpOutputMessage`
Use the given `Publisher` of `Publishers` to write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after each `Publisher<DataBuffer>`.

Specified by:
  `writeAndFlushWith` in interface `ReactiveHttpOutputMessage`
Parameters:
  `body` - the body content publisher
Returns:
  a `Mono` that indicates completion or error

### setComplete

public reactor.core.publisher.Mono<Void> 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 via `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.

Specified by:
  `setComplete` in interface `ReactiveHttpOutputMessage`
Returns:
  a `Mono` that indicates completion or error

### getNativeResponse

public static <T> T getNativeResponse(ServerHttpResponse response)
Return the native response of the underlying server API, if possible, also unwrapping `ServerHttpResponseDecorator` if 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

public String toString()

Overrides:
  `toString` in class `Object`