Provide default codecs config callback to custom codecs

As a follow-up of gh-23961, this change provides a way for custom codecs
to align with the default codecs' behavior on common features like
buffer size limits and logging request details.

Closes gh-24119
Co-authored-by: Rossen Stoyanchev <rstoyanchev@pivotal.io>
This commit is contained in:
Brian Clozel
2019-12-02 22:52:55 +01:00
parent 83683a13bb
commit a21df0cc6d
5 changed files with 100 additions and 6 deletions

View File

@@ -883,16 +883,44 @@ The following example shows how to do so for client-side requests:
[subs="verbatim,quotes"]
----
Consumer<ClientCodecConfigurer> consumer = configurer ->
configurer.defaultCodecs().enableLoggingRequestDetails(true);
configurer.defaultCodecs().enableLoggingRequestDetails(true);
WebClient webClient = WebClient.builder()
.exchangeStrategies(ExchangeStrategies.builder().codecs(consumer).build())
.build();
.exchangeStrategies(strategies -> strategies.codecs(consumer))
.build();
----
====
[[webflux-codecs-custom]]
==== Custom codecs
Applications can register custom codecs for supporting additional media types,
or specific behaviors that are not supported by the default codecs.
Some configuration options expressed by developers are enforced on default codecs.
Custom codecs might want to get a chance to align with those preferences,
like <<webflux-codecs-limits, enforcing buffering limits>>
or <<webflux-logging-sensitive-data, logging sensitive data>>.
The following example shows how to do so for client-side requests:
====
[source,java,indent=0]
[subs="verbatim,quotes"]
----
Consumer<ClientCodecConfigurer> consumer = configurer -> {
CustomDecoder customDecoder = new CustomDecoder();
configurer.customCodecs().decoder(customDecoder);
configurer.customCodecs().withDefaultCodecConfig(config ->
customDecoder.maxInMemorySize(config.maxInMemorySize())
);
}
WebClient webClient = WebClient.builder()
.exchangeStrategies(strategies -> strategies.codecs(consumer))
.build();
----
====
[[webflux-dispatcher-handler]]
== `DispatcherHandler`