[#1089] Correctly offer FullHttpContent if it is used to construct HttpPostRequestDecoder
This commit is contained in:
parent
4d969b964f
commit
30e7ab2f7d
@ -205,9 +205,15 @@ public class HttpPostRequestDecoder {
|
||||
if (!bodyToDecode) {
|
||||
throw new IncompatibleDataDecoderException("No Body to decode");
|
||||
}
|
||||
undecodedChunk = buffer();
|
||||
isLastChunk = true;
|
||||
parseBody();
|
||||
if (request instanceof HttpContent) {
|
||||
// Offer automatically if the given request is als type of HttpContent
|
||||
// See #1089
|
||||
offer((HttpContent) request);
|
||||
} else {
|
||||
undecodedChunk = buffer();
|
||||
isLastChunk = true;
|
||||
parseBody();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,7 @@ package io.netty.handler.codec.http.multipart;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.DecoderResult;
|
||||
import io.netty.handler.codec.http.DefaultFullHttpRequest;
|
||||
import io.netty.handler.codec.http.DefaultHttpContent;
|
||||
import io.netty.handler.codec.http.DefaultHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpHeaders;
|
||||
@ -28,6 +29,7 @@ import org.junit.Test;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/** {@link HttpPostRequestDecoder} test case. */
|
||||
public class HttpPostRequestDecoderTest {
|
||||
@ -70,4 +72,35 @@ public class HttpPostRequestDecoderTest {
|
||||
data, upload.getString(CharsetUtil.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
// See https://github.com/netty/netty/issues/1089
|
||||
@Test
|
||||
public void testFullHttpRequestUpload() throws Exception {
|
||||
final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
|
||||
|
||||
final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost");
|
||||
|
||||
req.setDecoderResult(DecoderResult.SUCCESS);
|
||||
req.headers().add(HttpHeaders.Names.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
|
||||
req.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
|
||||
|
||||
// Force to use memory-based data.
|
||||
final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
|
||||
|
||||
for (String data : Arrays.asList("", "\r", "\r\r", "\r\r\r")) {
|
||||
final String body =
|
||||
"--" + boundary + "\r\n" +
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" +
|
||||
"Content-Type: image/gif\r\n" +
|
||||
"\r\n" +
|
||||
data + "\r\n" +
|
||||
"--" + boundary + "--\r\n";
|
||||
|
||||
req.data().writeBytes(body.getBytes(CharsetUtil.UTF_8));
|
||||
}
|
||||
// Create decoder instance to test.
|
||||
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
|
||||
assertFalse(decoder.getBodyHttpDatas().isEmpty());
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user