title: Spring WebFlux 5.3.0 - WebClient.exchangeToMono()
body: <p>I've just upgraded to Webflux 5.3.0, and noticed that WebClient.exchange() method is now deprecated (<a href="https://github.com/spring-projects/spring-framework/issues/25751" rel="noreferrer">link</a>) in favor of new methos .exchangeToMono() and .exchangeToFlux()</p>
  <p>I had this code:</p>
  <pre><code>webClient
     .method(request.method)
     .uri(request.path)
     .body(request.bodyToMono&lt;ByteArray&gt;())
     .exchange()
     .flatMap { response -&gt;
        ServerResponse.
           .status(response.statusCode())
           .headers { it.addAll(response.headers().asHttpHeaders()) }
           .body(response.bodyToMono&lt;ByteArray&gt;())
     }
  </code></pre>
  <p>I had to refactor it into this:</p>
  <pre><code>   .exchangeToMono { response -&gt;
        ServerResponse.
           .status(response.statusCode())
           .headers { it.addAll(response.headers().asHttpHeaders()) }
           .body(response.bodyToMono&lt;ByteArray&gt;())
     }
  </code></pre>
  <p>However, apparently .exchangeToMono() calls .releaseIfNotConsumed(), which releases the unprocessed response body, and basically makes the server return an empty body</p>
  <p>So I had to refactor my code further:</p>
  <pre><code>   .exchangeToMono { response -&gt;
        response.bodyToMono&lt;ByteArray&gt;()
           .defaultIfEmpty(ByteArray(0))
           .flatMap { body -&gt;
              ServerResponse.
                 .status(response.statusCode())
                 .headers { it.addAll(response.headers().asHttpHeaders()) }
                 .bodyValue(body)
           }
     }
  </code></pre>
  <p>As far as I understand, .exchange() allows my proxy server to transmit the response body without actually processing it, while .exchangeToMono() forces me to process (buffer?) it. Is this correct?</p>
  <p>If so, what are the implications? Should I be okay with the change, or should I tweak the code somehow in order to make it transmit the response body without processing it? How would I do that?</p>
  <p>==========</p>
  <p><strong>tl;dr</strong> What is the practical difference between passing <code>.body(response.bodyToMono())</code> and <code>.bodyValue(body)</code>?</p>