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:
@@ -18,6 +18,7 @@ package org.springframework.http.codec.support;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -336,6 +337,18 @@ public class CodecConfigurerTests {
|
||||
assertFalse(encoders.containsAll(Arrays.asList(jacksonEncoder, jaxb2Encoder, protoEncoder)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withDefaultCodecConfig() {
|
||||
AtomicBoolean callbackCalled = new AtomicBoolean(false);
|
||||
this.configurer.defaultCodecs().enableLoggingRequestDetails(true);
|
||||
this.configurer.customCodecs().withDefaultCodecConfig(config -> {
|
||||
assertTrue(config.isEnableLoggingRequestDetails());
|
||||
callbackCalled.compareAndSet(false, true);
|
||||
});
|
||||
this.configurer.getReaders();
|
||||
assertTrue(callbackCalled.get());
|
||||
}
|
||||
|
||||
private Decoder<?> getNextDecoder(List<HttpMessageReader<?>> readers) {
|
||||
HttpMessageReader<?> reader = readers.get(this.index.getAndIncrement());
|
||||
assertEquals(DecoderHttpMessageReader.class, reader.getClass());
|
||||
|
||||
Reference in New Issue
Block a user