StringDecoder shouldn't chop off strings randomly

Issue: SPR-16337
This commit is contained in:
Arjen Poutsma
2018-02-01 11:57:44 +01:00
parent cfe7ff1c81
commit 609f173ebc
18 changed files with 338 additions and 128 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,7 +40,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ReactiveHttpInputMessage;
import org.springframework.lang.Nullable;
import static java.util.stream.Collectors.*;
import static java.util.stream.Collectors.joining;
/**
* Reader that supports a stream of {@link ServerSentEvent}s and also plain
@@ -56,7 +56,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
private static final DataBufferFactory bufferFactory = new DefaultDataBufferFactory();
private static final StringDecoder stringDecoder = StringDecoder.textPlainOnly(false);
private static final StringDecoder stringDecoder = StringDecoder.textPlainOnly();
@Nullable

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -188,12 +188,10 @@ abstract class AbstractCodecConfigurer implements CodecConfigurer {
result.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
result.add(new DecoderHttpMessageReader<>(new DataBufferDecoder()));
result.add(new DecoderHttpMessageReader<>(new ResourceDecoder()));
result.add(new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly(splitTextOnNewLine())));
result.add(new DecoderHttpMessageReader<>(StringDecoder.textPlainOnly()));
return result;
}
abstract boolean splitTextOnNewLine();
List<HttpMessageReader<?>> getObjectReaders() {
if (!this.registerDefaults) {
return Collections.emptyList();
@@ -216,7 +214,7 @@ abstract class AbstractCodecConfigurer implements CodecConfigurer {
return Collections.emptyList();
}
List<HttpMessageReader<?>> result = new ArrayList<>();
result.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes(splitTextOnNewLine())));
result.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
return result;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,11 +70,6 @@ public class DefaultClientCodecConfigurer extends AbstractCodecConfigurer implem
this.sseDecoder = decoder;
}
@Override
boolean splitTextOnNewLine() {
return false;
}
@Override
List<HttpMessageReader<?>> getObjectReaders() {
if (!shouldRegisterDefaults()) {
@@ -110,8 +105,7 @@ public class DefaultClientCodecConfigurer extends AbstractCodecConfigurer implem
}
else {
DefaultCustomCodecs customCodecs = getCustomCodecs();
partWriters = new ArrayList<>();
partWriters.addAll(super.getTypedWriters());
partWriters = new ArrayList<>(super.getTypedWriters());
if (customCodecs != null) {
partWriters.addAll(customCodecs.getTypedWriters());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -66,11 +66,6 @@ public class DefaultServerCodecConfigurer extends AbstractCodecConfigurer implem
this.sseEncoder = encoder;
}
@Override
boolean splitTextOnNewLine() {
return true;
}
@Override
List<HttpMessageReader<?>> getTypedReaders() {
if (!shouldRegisterDefaults()) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -269,6 +269,11 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
return this.dataBuffer.capacity(newCapacity);
}
@Override
public byte getByte(int index) {
return this.dataBuffer.getByte(index);
}
@Override
public byte read() {
return this.dataBuffer.read();