Return null in HttpPostRequestEncoder (#9352)
Motivation: If the encoded value of a form element happens to exactly hit the chunk limit (8096 bytes), the post request encoder will throw a NullPointerException. Modifications: Catch the null case and return. Result: No NPE.
This commit is contained in:
parent
306299323c
commit
d07d7e2b9a
@ -977,7 +977,11 @@ public class HttpPostRequestEncoder implements ChunkedInput<HttpContent> {
|
||||
if (buffer.capacity() == 0) {
|
||||
currentData = null;
|
||||
if (currentBuffer == null) {
|
||||
currentBuffer = delimiter;
|
||||
if (delimiter == null) {
|
||||
return null;
|
||||
} else {
|
||||
currentBuffer = delimiter;
|
||||
}
|
||||
} else {
|
||||
if (delimiter != null) {
|
||||
currentBuffer = wrappedBuffer(currentBuffer, delimiter);
|
||||
|
@ -18,10 +18,12 @@ package io.netty.handler.codec.http.multipart;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.http.DefaultHttpRequest;
|
||||
import io.netty.handler.codec.http.DefaultFullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpConstants;
|
||||
import io.netty.handler.codec.http.HttpContent;
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
import io.netty.handler.codec.http.HttpRequest;
|
||||
import io.netty.handler.codec.http.HttpVersion;
|
||||
import io.netty.handler.codec.http.LastHttpContent;
|
||||
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder.EncoderMode;
|
||||
@ -443,4 +445,27 @@ public class HttpPostRequestEncoderTest {
|
||||
+ readable, expectedSize);
|
||||
httpContent.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeChunkedContent() throws Exception {
|
||||
HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
|
||||
HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(req, false);
|
||||
|
||||
int length = 8077 + 8096;
|
||||
char[] array = new char[length];
|
||||
Arrays.fill(array, 'a');
|
||||
String longText = new String(array);
|
||||
|
||||
encoder.addBodyAttribute("data", longText);
|
||||
encoder.addBodyAttribute("moreData", "abcd");
|
||||
|
||||
assertNotNull(encoder.finalizeRequest());
|
||||
|
||||
while (!encoder.isEndOfInput()) {
|
||||
encoder.readChunk((ByteBufAllocator) null).release();
|
||||
}
|
||||
|
||||
assertTrue(encoder.isEndOfInput());
|
||||
encoder.cleanFiles();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user