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
This commit is contained in:
Brian Clozel
2019-11-29 22:26:52 +01:00
committed by Rossen Stoyanchev
parent 17e2a0c7ea
commit d4209392d2
18 changed files with 344 additions and 43 deletions

View File

@@ -268,6 +268,14 @@ public class CodecConfigurerTests {
assertEncoderInstance(jaxb2Encoder);
}
@Test
public void cloneConfigurer() {
CodecConfigurer clone = this.configurer.clone();
this.configurer.registerDefaults(false);
assertThat(this.configurer.getReaders().size()).isEqualTo(0);
assertThat(clone.getReaders().size()).isEqualTo(11);
}
private Decoder<?> getNextDecoder(List<HttpMessageReader<?>> readers) {
HttpMessageReader<?> reader = readers.get(this.index.getAndIncrement());
assertThat(reader.getClass()).isEqualTo(DecoderHttpMessageReader.class);