Allow ExchangeStrategies customizations in WebClient
Prior to this commit, developers could configure their WebClient to use
their custom `ExchangeStrategies`, by providing it in the
`WebClient.Builder` chain.
Once created, an `ExchangeStrategies` instance is not mutable, which
makes it hard for further customizations by other components. In the
case of the reported issue, other components would override the default
configuration for the codecs maxInMemorySize.
This commit makes the `ExchangeStrategies` mutable and uses that fact to
further customize them with a new `WebClient.Builder#exchangeStrategies`
`Consumer` variant. This commit is also deprecating those mutating
variants in favor of a new `WebClient.Builder#exchangeStrategies` that
takes a `ExchangeStrategies#Builder` directly and avoids mutation issues
altogether.
Closes gh-23961
pull/24117/head
Brian Clozel6 years agocommitted byRossen Stoyanchev
@ -43,13 +43,18 @@ final class DefaultExchangeStrategiesBuilder implements ExchangeStrategies.Build
@@ -43,13 +43,18 @@ final class DefaultExchangeStrategiesBuilder implements ExchangeStrategies.Build
@ -69,19 +74,29 @@ final class DefaultExchangeStrategiesBuilder implements ExchangeStrategies.Build
@@ -69,19 +74,29 @@ final class DefaultExchangeStrategiesBuilder implements ExchangeStrategies.Build
@ -79,14 +80,16 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@@ -79,14 +80,16 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@ -108,7 +111,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@@ -108,7 +111,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@ -203,9 +206,23 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@@ -203,9 +206,23 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@ -229,7 +246,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@@ -229,7 +246,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@ -254,6 +271,19 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@@ -254,6 +271,19 @@ final class DefaultWebClientBuilder implements WebClient.Builder {
@ -41,28 +41,26 @@ The following example configures <<web-reactive.adoc#webflux-codecs, HTTP codecs
@@ -41,28 +41,26 @@ The following example configures <<web-reactive.adoc#webflux-codecs, HTTP codecs
Once built, a `WebClient` instance is immutable. However, you can clone it and build a
@ -95,7 +93,44 @@ modified copy without affecting the original instance, as the following example
@@ -95,7 +93,44 @@ modified copy without affecting the original instance, as the following example
// client2 has filterA, filterB, filterC, filterD
----
[[webflux-client-builder-maxinmemorysize]]
=== MaxInMemorySize
Spring WebFlux configures by default a maximum size for buffering data in-memory when decoding
HTTP responses with the `WebClient`. This avoids application memory issues if the received
response is much larger than expected.
The default configured value of 256KB might not be enough for your use case, and your application
might hit that limit with the following:
----
org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer
----
You can configure this limit on all default codecs with the following code sample: