delete Other "Content-" MIME Header Fields exception (#9122)
delete Other "Content-" MIME Header Fields exception Motivation: RFC7578 4.8. Other "Content-" Header Fields The multipart/form-data media type does not support any MIME header fields in parts other than Content-Type, Content-Disposition, and (in limited circumstances) Content-Transfer-Encoding. Other header fields MUST NOT be included and MUST be ignored. Modification: Ignore other Content types. Result: Other "Content-" Header Fields should be ignored no exception
This commit is contained in:
parent
9d5420987a
commit
68f2242ac4
@ -752,8 +752,6 @@ public class HttpPostMultipartRequestDecoder implements InterfaceHttpPostRequest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new ErrorDataDecoderException("Unknown Params: " + newline);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Is it a FileUpload
|
// Is it a FileUpload
|
||||||
|
@ -413,6 +413,39 @@ public class HttpPostRequestDecoderTest {
|
|||||||
decoder.destroy();
|
decoder.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDecodeOtherMimeHeaderFields() throws Exception {
|
||||||
|
final String boundary = "74e78d11b0214bdcbc2f86491eeb4902";
|
||||||
|
String filecontent = "123456";
|
||||||
|
|
||||||
|
final String body = "--" + boundary + "\r\n" +
|
||||||
|
"Content-Disposition: form-data; name=\"file\"; filename=" + "\"" + "attached.txt" + "\"" +
|
||||||
|
"\r\n" +
|
||||||
|
"Content-Type: application/octet-stream" + "\r\n" +
|
||||||
|
"Content-Encoding: gzip" + "\r\n" +
|
||||||
|
"\r\n" +
|
||||||
|
filecontent +
|
||||||
|
"\r\n" +
|
||||||
|
"--" + boundary + "--";
|
||||||
|
|
||||||
|
final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
|
||||||
|
HttpMethod.POST,
|
||||||
|
"http://localhost",
|
||||||
|
Unpooled.wrappedBuffer(body.getBytes()));
|
||||||
|
req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
|
||||||
|
req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
|
||||||
|
final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
|
||||||
|
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
|
||||||
|
assertFalse(decoder.getBodyHttpDatas().isEmpty());
|
||||||
|
InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
|
||||||
|
assertTrue("the item should be a FileUpload", part1 instanceof FileUpload);
|
||||||
|
FileUpload fileUpload = (FileUpload) part1;
|
||||||
|
byte[] fileBytes = fileUpload.get();
|
||||||
|
assertTrue("the filecontent should not be decoded", filecontent.equals(new String(fileBytes)));
|
||||||
|
decoder.destroy();
|
||||||
|
req.release();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultipartRequestWithFileInvalidCharset() throws Exception {
|
public void testMultipartRequestWithFileInvalidCharset() throws Exception {
|
||||||
final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
|
final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
|
||||||
|
Loading…
Reference in New Issue
Block a user