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-24118 Co-authored-by: Rossen Stoyanchev <rstoyanchev@pivotal.io>
This commit is contained in:
@@ -950,7 +950,7 @@ The following example shows how to do so for client-side requests:
|
||||
configurer.defaultCodecs().enableLoggingRequestDetails(true);
|
||||
|
||||
WebClient webClient = WebClient.builder()
|
||||
.exchangeStrategies(ExchangeStrategies.builder().codecs(consumer).build())
|
||||
.exchangeStrategies(strategies -> strategies.codecs(consumer))
|
||||
.build();
|
||||
----
|
||||
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
||||
@@ -959,12 +959,53 @@ The following example shows how to do so for client-side requests:
|
||||
val consumer: (ClientCodecConfigurer) -> Unit = { configurer -> configurer.defaultCodecs().enableLoggingRequestDetails(true) }
|
||||
|
||||
val webClient = WebClient.builder()
|
||||
.exchangeStrategies(ExchangeStrategies.builder().codecs(consumer).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",role="primary"]
|
||||
.Java
|
||||
----
|
||||
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();
|
||||
----
|
||||
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
||||
.Kotlin
|
||||
----
|
||||
val consumer: (ClientCodecConfigurer) -> Unit = { configurer ->
|
||||
val customDecoder = CustomDecoder()
|
||||
configurer.customCodecs().decoder(customDecoder)
|
||||
configurer.customCodecs().withDefaultCodecConfig({ config ->
|
||||
customDecoder.maxInMemorySize(config.maxInMemorySize())
|
||||
})
|
||||
}
|
||||
|
||||
val webClient = WebClient.builder()
|
||||
.exchangeStrategies({ strategies -> strategies.codecs(consumer) })
|
||||
.build()
|
||||
----
|
||||
|
||||
[[webflux-dispatcher-handler]]
|
||||
== `DispatcherHandler`
|
||||
|
||||
Reference in New Issue
Block a user