Skip to content

Commit 4c863f3

Browse files
committed
Revise documentation on using WebClient::exchange
This commit revised the paragraph regarding the need to consume or release the ClientResponse body when using WebClient::exchange. Closes gh-23498
1 parent 37398c6 commit 4c863f3

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/docs/asciidoc/web/webflux-webclient.adoc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,20 @@ At this level, you can also create a full `ResponseEntity`:
462462
Note that (unlike `retrieve()`), with `exchange()`, there are no automatic error signals for
463463
4xx and 5xx responses. You have to check the status code and decide how to proceed.
464464

465-
CAUTION: When you use `exchange()`, you must always use any of the `body` or `toEntity` methods of
466-
`ClientResponse` to ensure resources are released and to avoid potential issues with HTTP
467-
connection pooling. You can use `bodyToMono(Void.class)` if no response content is
468-
expected. However, if the response does have content, the connection
469-
is closed and is not placed back in the pool.
470-
465+
[CAUTION]
466+
====
467+
When using `exchange()`, you have to make sure that the body is always consumed or released,
468+
even when an exception occurs (see <<core.adoc#databuffers-using,Using DataBuffer>>).
469+
Typically, you do this by invoking either `bodyTo*` or `toEntity*` on `ClientResponse`
470+
to convert the body into an object of the desired type, but
471+
you can also invoke `releaseBody()` to discard the body contents without consuming it or
472+
`toBodilessEntity()` to get just the status and headers (while discarding the body).
473+
474+
Finally, there is `bodyToMono(Void.class)`, which should only be used if no response content is
475+
expected.
476+
If the response does have content, the connection is closed and is not placed back in the pool,
477+
because it is not left in a reusable state.
478+
====
471479

472480

473481

0 commit comments

Comments
 (0)