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
parent d7023fd02b
commit b3020bc484
18 changed files with 345 additions and 46 deletions

View File

@@ -169,18 +169,19 @@ public interface RSocketRequester {
RSocketRequester.Builder setupMetadata(Object value, @Nullable MimeType mimeType);
/**
* Provide {@link RSocketStrategies} to use.
* <p>By default this is based on default settings of
* {@link RSocketStrategies.Builder} but may be further customized via
* {@link #rsocketStrategies(Consumer)}.
* Provide the {@link RSocketStrategies} to use.
* <p>This is useful for changing the default settings, yet still allowing
* further customizations via {@link #rsocketStrategies(Consumer)}.
* If not set, defaults are obtained from {@link RSocketStrategies#builder()}.
* @param strategies the strategies to use
*/
RSocketRequester.Builder rsocketStrategies(@Nullable RSocketStrategies strategies);
/**
* Customize the {@link RSocketStrategies}.
* <p>By default this starts out as {@link RSocketStrategies#builder()}.
* However if strategies were {@link #rsocketStrategies(RSocketStrategies) set}
* explicitly, then they are {@link RSocketStrategies#mutate() mutated}.
* <p>Allows further customization on {@link RSocketStrategies},
* mutating them if they were {@link #rsocketStrategies(RSocketStrategies) set},
* or starting from {@link RSocketStrategies#builder()} defaults}.
*/
RSocketRequester.Builder rsocketStrategies(Consumer<RSocketStrategies.Builder> configurer);