[1575] Correctly parse Content-Type value

This commit is contained in:
Norman Maurer 2013-07-14 15:48:00 +02:00
parent a07abee55f
commit 32b671f4dc
2 changed files with 24 additions and 9 deletions

View File

@ -2029,20 +2029,19 @@ public class HttpPostRequestDecoder {
* @return the array of 2 Strings
*/
private static String[] splitHeaderContentType(String sb) {
int size = sb.length();
int aStart;
int aEnd;
int bStart;
int bEnd;
aStart = HttpPostBodyUtil.findNonWhitespace(sb, 0);
aEnd = HttpPostBodyUtil.findWhitespace(sb, aStart);
if (aEnd >= size) {
aEnd = sb.indexOf(';');
if (aEnd == -1) {
return new String[] { sb, "" };
}
if (sb.charAt(aEnd) == ';') {
if (sb.charAt(aEnd - 1) == ' ') {
aEnd--;
}
bStart = HttpPostBodyUtil.findNonWhitespace(sb, aEnd);
bStart = HttpPostBodyUtil.findNonWhitespace(sb, aEnd + 1);
bEnd = HttpPostBodyUtil.findEndOfString(sb);
return new String[] { sb.substring(aStart, aEnd), sb.substring(bStart, bEnd) };
}

View File

@ -32,15 +32,31 @@ import static org.junit.Assert.*;
/** {@link HttpPostRequestDecoder} test case. */
public class HttpPostRequestDecoderTest {
@Test
public void testBinaryStreamUpload() throws Exception {
final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
@Test
public void testBinaryStreamUploadWithSpace() throws Exception {
testBinaryStreamUpload(true);
}
// https://github.com/netty/netty/issues/1575
@Test
public void testBinaryStreamUploadWithoutSpace() throws Exception {
testBinaryStreamUpload(false);
}
private static void testBinaryStreamUpload(boolean withSpace) throws Exception {
final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
final String contentTypeValue;
if (withSpace) {
contentTypeValue = "multipart/form-data; boundary=" + boundary;
} else {
contentTypeValue = "multipart/form-data;boundary=" + boundary;
}
final DefaultHttpRequest req = new DefaultHttpRequest(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.CONTENT_TYPE, contentTypeValue);
req.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
// Force to use memory-based data.