org.springframework.web.reactive.function.client

## Interface ClientResponse

All Known Implementing Classes:
  ClientResponseWrapper

    public interface ClientResponse

Represents an HTTP response, as returned by `WebClient` and also `ExchangeFunction`. Provides access to the response status and headers, and also methods to consume the response body.

NOTE: When using a `ClientResponse` through the `WebClient` `exchange()` method, you have to make sure that the body is consumed or released by using one of the following methods:

- `body(BodyExtractor)`
- `bodyToMono(Class)` or `bodyToMono(ParameterizedTypeReference)`
- `bodyToFlux(Class)` or `bodyToFlux(ParameterizedTypeReference)`
- `toEntity(Class)` or `toEntity(ParameterizedTypeReference)`
- `toEntityList(Class)` or `toEntityList(ParameterizedTypeReference)`
- `toBodilessEntity()`
- `releaseBody()`

You can also use `bodyToMono(Void.class)` if no response content is expected. However keep in mind the connection will be closed, instead of being placed back in the pool, if any content does arrive. This is in contrast to `releaseBody()` which does consume the full body and releases any content received.

Since:
  5.0
Author:
  Brian Clozel, Arjen Poutsma

### Nested Class Summary

Nested Classes
`static interface` `ClientResponse.Builder` Defines a builder for a response.
`static interface` `ClientResponse.Headers` Represents the headers of the HTTP response.

### Method Summary

All Methods Static Methods Instance Methods Abstract Methods Default Methods
`<T> T` `body(BodyExtractor<T,? super org.springframework.http.client.reactive.ClientHttpResponse> extractor)` Extract the body with the given `BodyExtractor`.
`<T> reactor.core.publisher.Flux<T>` `bodyToFlux(Class<? extends T> elementClass)` Extract the body to a `Flux`.
`<T> reactor.core.publisher.Flux<T>` `bodyToFlux(org.springframework.core.ParameterizedTypeReference<T> elementTypeRef)` Extract the body to a `Flux`.
`<T> reactor.core.publisher.Mono<T>` `bodyToMono(Class<? extends T> elementClass)` Extract the body to a `Mono`.
`<T> reactor.core.publisher.Mono<T>` `bodyToMono(org.springframework.core.ParameterizedTypeReference<T> elementTypeRef)` Extract the body to a `Mono`.
`org.springframework.util.MultiValueMap<String,org.springframework.http.ResponseCookie>` `cookies()` Return the cookies of this response.
`static ClientResponse.Builder` `create(org.springframework.http.HttpStatus statusCode)` Create a response builder with the given status code and using default strategies for reading the body.
`static ClientResponse.Builder` `create(org.springframework.http.HttpStatus statusCode, ExchangeStrategies strategies)` Create a response builder with the given status code and strategies for reading the body.
`static ClientResponse.Builder` `create(org.springframework.http.HttpStatus statusCode, List<org.springframework.http.codec.HttpMessageReader<?>> messageReaders)` Create a response builder with the given status code and message body readers.
`static ClientResponse.Builder` `create(int statusCode, ExchangeStrategies strategies)` Create a response builder with the given raw status code and strategies for reading the body.
`reactor.core.publisher.Mono<WebClientResponseException>` `createException()` Create a `WebClientResponseException` that contains the response status, headers, body, and the originating request.
`static ClientResponse.Builder` `from(ClientResponse other)` Create a builder with the status, headers, and cookies of the given response.
`ClientResponse.Headers` `headers()` Return the headers of this response.
`String` `logPrefix()` Return a log message prefix to use to correlate messages for this exchange.
`int` `rawStatusCode()` Return the (potentially non-standard) status code of this response.
`reactor.core.publisher.Mono<Void>` `releaseBody()` Release the body of this response.
`org.springframework.http.HttpStatus` `statusCode()` Return the HTTP status code as an `HttpStatus` enum value.
`ExchangeStrategies` `strategies()` Return the strategies used to convert the body of this response.
`reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Void>>` `toBodilessEntity()` Return this response as a delayed `ResponseEntity` containing status and headers, but no body.
`<T> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<T>>` `toEntity(Class<T> bodyClass)` Return this response as a delayed `ResponseEntity`.
`<T> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<T>>` `toEntity(org.springframework.core.ParameterizedTypeReference<T> bodyTypeReference)` Return this response as a delayed `ResponseEntity`.
`<T> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<List<T>>>` `toEntityList(Class<T> elementClass)` Return this response as a delayed list of `ResponseEntity`s.
`<T> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<List<T>>>` `toEntityList(org.springframework.core.ParameterizedTypeReference<T> elementTypeRef)` Return this response as a delayed list of `ResponseEntity`s.

### Method Detail

#### statusCode

    org.springframework.http.HttpStatus statusCode()

Return the HTTP status code as an `HttpStatus` enum value.

Returns:
  the HTTP status as an HttpStatus enum value (never `null`)
Throws:
  `IllegalArgumentException` - in case of an unknown HTTP status code
Since:
  #getRawStatusCode()
See Also:
  `HttpStatus.valueOf(int)`

#### rawStatusCode

    int rawStatusCode()

Return the (potentially non-standard) status code of this response.

Returns:
  the HTTP status as an integer value
Since:
  5.1
See Also:
  `statusCode()`, `HttpStatus.resolve(int)`

#### headers

    ClientResponse.Headers headers()

Return the headers of this response.

#### cookies

    org.springframework.util.MultiValueMap<String,org.springframework.http.ResponseCookie> cookies()

Return the cookies of this response.

#### strategies

    ExchangeStrategies strategies()

Return the strategies used to convert the body of this response.

#### body

    <T> T body(BodyExtractor<T,? super org.springframework.http.client.reactive.ClientHttpResponse> extractor)

Extract the body with the given `BodyExtractor`.

Type Parameters:
  `T` - the type of the body returned
Parameters:
  `extractor` - the `BodyExtractor` that reads from the response
Returns:
  the extracted body

#### bodyToMono

    <T> reactor.core.publisher.Mono<T> bodyToMono(Class<? extends T> elementClass)

Extract the body to a `Mono`.

Type Parameters:
  `T` - the element type
Parameters:
  `elementClass` - the class of element in the `Mono`
Returns:
  a mono containing the body of the given type `T`

#### bodyToMono

    <T> reactor.core.publisher.Mono<T> bodyToMono(org.springframework.core.ParameterizedTypeReference<T> elementTypeRef)

Extract the body to a `Mono`.

Type Parameters:
  `T` - the element type
Parameters:
  `elementTypeRef` - the type reference of element in the `Mono`
Returns:
  a mono containing the body of the given type `T`

#### bodyToFlux

    <T> reactor.core.publisher.Flux<T> bodyToFlux(Class<? extends T> elementClass)

Extract the body to a `Flux`.

Type Parameters:
  `T` - the element type
Parameters:
  `elementClass` - the class of elements in the `Flux`
Returns:
  a flux containing the body of the given type `T`

#### bodyToFlux

    <T> reactor.core.publisher.Flux<T> bodyToFlux(org.springframework.core.ParameterizedTypeReference<T> elementTypeRef)

Extract the body to a `Flux`.

Type Parameters:
  `T` - the element type
Parameters:
  `elementTypeRef` - the type reference of elements in the `Flux`
Returns:
  a flux containing the body of the given type `T`

#### releaseBody

    reactor.core.publisher.Mono<Void> releaseBody()

Release the body of this response.

Returns:
  a completion signal
Since:
  5.2
See Also:
  `DataBufferUtils.release(DataBuffer)`

#### toEntity

    <T> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<T>> toEntity(Class<T> bodyClass)

Return this response as a delayed `ResponseEntity`.

Type Parameters:
  `T` - response body type
Parameters:
  `bodyClass` - the expected response body type
Returns:
  `Mono` with the `ResponseEntity`

#### toEntity

    <T> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<T>> toEntity(org.springframework.core.ParameterizedTypeReference<T> bodyTypeReference)

Return this response as a delayed `ResponseEntity`.

Type Parameters:
  `T` - response body type
Parameters:
  `bodyTypeReference` - a type reference describing the expected response body type
Returns:
  `Mono` with the `ResponseEntity`

#### toEntityList

    <T> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<List<T>>> toEntityList(Class<T> elementClass)

Return this response as a delayed list of `ResponseEntity`s.

Type Parameters:
  `T` - the type of elements in the list
Parameters:
  `elementClass` - the expected response body list element class
Returns:
  `Mono` with the list of `ResponseEntity`s

#### toEntityList

    <T> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<List<T>>> toEntityList(org.springframework.core.ParameterizedTypeReference<T> elementTypeRef)

Return this response as a delayed list of `ResponseEntity`s.

Type Parameters:
  `T` - the type of elements in the list
Parameters:
  `elementTypeRef` - the expected response body list element reference type
Returns:
  `Mono` with the list of `ResponseEntity`s

#### toBodilessEntity

    reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<Void>> toBodilessEntity()

Return this response as a delayed `ResponseEntity` containing status and headers, but no body. Calling this method will release the body of the response.

Returns:
  `Mono` with the bodiless `ResponseEntity`
Since:
  5.2

#### createException

    reactor.core.publisher.Mono<WebClientResponseException> createException()

Create a `WebClientResponseException` that contains the response status, headers, body, and the originating request.

Returns:
  a `Mono` with the created exception
Since:
  5.2

#### logPrefix

    String logPrefix()

Return a log message prefix to use to correlate messages for this exchange.

The prefix is based on ClientRequest.logPrefix(), which itself is based on the value of the `LOG_ID_ATTRIBUTE` request attribute, further surrounded with "[" and "]".

Returns:
  the log message prefix or an empty String if the `LOG_ID_ATTRIBUTE` is not set
Since:
  5.2.3

#### from

    static ClientResponse.Builder from(ClientResponse other)

Create a builder with the status, headers, and cookies of the given response.

Parameters:
  `other` - the response to copy the status, headers, and cookies from
Returns:
  the created builder

#### create

    static ClientResponse.Builder create(org.springframework.http.HttpStatus statusCode)

Create a response builder with the given status code and using default strategies for reading the body.

Parameters:
  `statusCode` - the status code
Returns:
  the created builder

#### create

    static ClientResponse.Builder create(org.springframework.http.HttpStatus statusCode,
                                         ExchangeStrategies strategies)

Create a response builder with the given status code and strategies for reading the body.

Parameters:
  `statusCode` - the status code
  `strategies` - the strategies
Returns:
  the created builder

#### create

    static ClientResponse.Builder create(int statusCode,
                                         ExchangeStrategies strategies)

Create a response builder with the given raw status code and strategies for reading the body.

Parameters:
  `statusCode` - the status code
  `strategies` - the strategies
Returns:
  the created builder
Since:
  5.1.9

#### create

    static ClientResponse.Builder create(org.springframework.http.HttpStatus statusCode,
                                         List<org.springframework.http.codec.HttpMessageReader<?>> messageReaders)

Create a response builder with the given status code and message body readers.

Parameters:
  `statusCode` - the status code
  `messageReaders` - the message readers
Returns:
  the created builder