Fix regression in client codecs
Restore the correct client-side default for whether StringDecoder
should split on new lines. It is true forthe server and false for the
client by default.
The regression was introduced in the recent refactoring:
f8a21ab11b (diff-0175d58138b2e8b2bec087ffe0495340)
This commit is contained in:
parent
a8162c03f9
commit
d1db249584
|
@ -181,7 +181,7 @@ public abstract class AbstractCodecConfigurer {
|
|||
/**
|
||||
* A registry and a factory for built-in HTTP message readers and writers.
|
||||
*/
|
||||
public static class DefaultCodecConfigurer {
|
||||
public abstract static class DefaultCodecConfigurer {
|
||||
|
||||
private boolean suppressed = false;
|
||||
|
||||
|
@ -280,13 +280,9 @@ public abstract class AbstractCodecConfigurer {
|
|||
}
|
||||
|
||||
|
||||
protected void addStringReaderTextOnlyTo(List<HttpMessageReader<?>> result) {
|
||||
addReaderTo(result, () -> new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly(true)));
|
||||
}
|
||||
protected abstract void addStringReaderTextOnlyTo(List<HttpMessageReader<?>> result);
|
||||
|
||||
protected void addStringReaderTo(List<HttpMessageReader<?>> result) {
|
||||
addReaderTo(result, () -> new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true)));
|
||||
}
|
||||
protected abstract void addStringReaderTo(List<HttpMessageReader<?>> result);
|
||||
|
||||
protected void addStringWriterTextPlainOnlyTo(List<HttpMessageWriter<?>> result) {
|
||||
addWriterTo(result, () -> new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.http.codec;
|
|||
import java.util.List;
|
||||
|
||||
import org.springframework.core.codec.Decoder;
|
||||
import org.springframework.core.codec.StringDecoder;
|
||||
import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
||||
|
||||
/**
|
||||
|
@ -79,6 +80,14 @@ public class ClientCodecConfigurer extends AbstractCodecConfigurer {
|
|||
|
||||
// Internal methods for building a list of default readers or writers...
|
||||
|
||||
protected void addStringReaderTextOnlyTo(List<HttpMessageReader<?>> result) {
|
||||
addReaderTo(result, () -> new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly(false)));
|
||||
}
|
||||
|
||||
protected void addStringReaderTo(List<HttpMessageReader<?>> result) {
|
||||
addReaderTo(result, () -> new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(false)));
|
||||
}
|
||||
|
||||
private void addServerSentEventReaderTo(List<HttpMessageReader<?>> result) {
|
||||
addReaderTo(result, () -> findReader(ServerSentEventHttpMessageReader.class, () -> {
|
||||
Decoder<?> decoder = null;
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.springframework.http.codec;
|
|||
import java.util.List;
|
||||
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.core.codec.StringDecoder;
|
||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||
|
||||
/**
|
||||
|
@ -78,6 +79,14 @@ public class ServerCodecConfigurer extends AbstractCodecConfigurer {
|
|||
|
||||
// Internal methods for building a list of default readers or writers...
|
||||
|
||||
protected void addStringReaderTextOnlyTo(List<HttpMessageReader<?>> result) {
|
||||
addReaderTo(result, () -> new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly(true)));
|
||||
}
|
||||
|
||||
protected void addStringReaderTo(List<HttpMessageReader<?>> result) {
|
||||
addReaderTo(result, () -> new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true)));
|
||||
}
|
||||
|
||||
private void addServerSentEventWriterTo(List<HttpMessageWriter<?>> result) {
|
||||
addWriterTo(result, () -> findWriter(ServerSentEventHttpMessageWriter.class, () -> {
|
||||
Encoder<?> encoder = null;
|
||||
|
|
|
@ -15,11 +15,16 @@
|
|||
*/
|
||||
package org.springframework.http.codec;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.ByteArrayDecoder;
|
||||
import org.springframework.core.codec.ByteArrayEncoder;
|
||||
import org.springframework.core.codec.ByteBufferDecoder;
|
||||
|
@ -31,6 +36,7 @@ import org.springframework.core.codec.Decoder;
|
|||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.core.codec.ResourceDecoder;
|
||||
import org.springframework.core.codec.StringDecoder;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||
|
@ -112,10 +118,17 @@ public class ClientCodecConfigurerTests {
|
|||
return ((EncoderHttpMessageWriter) writer).getEncoder();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void assertStringDecoder(Decoder<?> decoder, boolean textOnly) {
|
||||
assertEquals(StringDecoder.class, decoder.getClass());
|
||||
assertTrue(decoder.canDecode(forClass(String.class), MimeTypeUtils.TEXT_PLAIN));
|
||||
assertEquals(!textOnly, decoder.canDecode(forClass(String.class), MediaType.TEXT_EVENT_STREAM));
|
||||
|
||||
Flux<String> decoded = (Flux<String>) decoder.decode(
|
||||
Flux.just(new DefaultDataBufferFactory().wrap("line1\nline2".getBytes(StandardCharsets.UTF_8))),
|
||||
ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN, Collections.emptyMap());
|
||||
|
||||
assertEquals(Collections.singletonList("line1\nline2"), decoded.collectList().block(Duration.ZERO));
|
||||
}
|
||||
|
||||
private void assertStringEncoder(Encoder<?> encoder, boolean textOnly) {
|
||||
|
|
|
@ -282,7 +282,19 @@ public class CodecConfigurerTests {
|
|||
private static class TestCodecConfigurer extends AbstractCodecConfigurer {
|
||||
|
||||
private TestCodecConfigurer() {
|
||||
super(new DefaultCodecConfigurer());
|
||||
super(new TestDefaultCodecConfigurer());
|
||||
}
|
||||
|
||||
|
||||
private static class TestDefaultCodecConfigurer extends DefaultCodecConfigurer {
|
||||
|
||||
protected void addStringReaderTextOnlyTo(List<HttpMessageReader<?>> result) {
|
||||
addReaderTo(result, () -> new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly(true)));
|
||||
}
|
||||
|
||||
protected void addStringReaderTo(List<HttpMessageReader<?>> result) {
|
||||
addReaderTo(result, () -> new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(true)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,11 +15,17 @@
|
|||
*/
|
||||
package org.springframework.http.codec;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.ByteArrayDecoder;
|
||||
import org.springframework.core.codec.ByteArrayEncoder;
|
||||
import org.springframework.core.codec.ByteBufferDecoder;
|
||||
|
@ -31,6 +37,7 @@ import org.springframework.core.codec.Decoder;
|
|||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.core.codec.ResourceDecoder;
|
||||
import org.springframework.core.codec.StringDecoder;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.json.Jackson2JsonDecoder;
|
||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||
|
@ -112,10 +119,17 @@ public class ServerCodecConfigurerTests {
|
|||
return ((EncoderHttpMessageWriter) writer).getEncoder();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void assertStringDecoder(Decoder<?> decoder, boolean textOnly) {
|
||||
assertEquals(StringDecoder.class, decoder.getClass());
|
||||
assertTrue(decoder.canDecode(forClass(String.class), MimeTypeUtils.TEXT_PLAIN));
|
||||
assertEquals(!textOnly, decoder.canDecode(forClass(String.class), MediaType.TEXT_EVENT_STREAM));
|
||||
|
||||
Flux<String> flux = (Flux<String>) decoder.decode(
|
||||
Flux.just(new DefaultDataBufferFactory().wrap("line1\nline2".getBytes(StandardCharsets.UTF_8))),
|
||||
ResolvableType.forClass(String.class), MimeTypeUtils.TEXT_PLAIN, Collections.emptyMap());
|
||||
|
||||
assertEquals(Arrays.asList("line1\n", "line2"), flux.collectList().block(Duration.ZERO));
|
||||
}
|
||||
|
||||
private void assertStringEncoder(Encoder<?> encoder, boolean textOnly) {
|
||||
|
|
Loading…
Reference in New Issue