use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project netty by netty.
the class HttpPostRequestDecoderTest method testNotLeakWhenWrapIllegalArgumentException.
private static void testNotLeakWhenWrapIllegalArgumentException(ByteBuf buf) {
buf.writeCharSequence("a=b&foo=%22bar%22&==", CharsetUtil.US_ASCII);
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", buf);
try {
new HttpPostStandardRequestDecoder(request).destroy();
} finally {
assertTrue(request.release());
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project netty by netty.
the class HttpPostRequestDecoderTest method testDecodeContentDispositionFieldParameters.
// https://github.com/netty/netty/pull/7265
@Test
public void testDecodeContentDispositionFieldParameters() throws Exception {
final String boundary = "74e78d11b0214bdcbc2f86491eeb4902";
String encoding = "utf-8";
String filename = "attached_файл.txt";
String filenameEncoded = URLEncoder.encode(filename, encoding);
final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename*=" + encoding + "''" + filenameEncoded + "\r\n\r\n" + "foo\r\n" + "\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);
final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
assertFalse(decoder.getBodyHttpDatas().isEmpty());
InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
assertTrue(part1 instanceof FileUpload, "the item should be a FileUpload");
FileUpload fileUpload = (FileUpload) part1;
assertEquals(filename, fileUpload.getFilename(), "the filename should be decoded");
decoder.destroy();
assertTrue(req.release());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project netty by netty.
the class HttpPostRequestDecoderTest method testMultipartRequestWithFieldInvalidCharset.
@Test
public void testMultipartRequestWithFieldInvalidCharset() throws Exception {
final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost");
req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
// Force to use memory-based data.
final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
final String aData = "some data would be here. the data should be long enough that it " + "will be longer than the original buffer length of 256 bytes in " + "the HttpPostRequestDecoder in order to trigger the issue. Some more " + "data just to be on the safe side.";
final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"root\"\r\n" + "Content-Type: text/plain; charset=ABCD\r\n" + "\r\n" + aData + "\r\n" + "--" + boundary + "--\r\n";
req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8));
// Create decoder instance to test.
try {
new HttpPostRequestDecoder(inMemoryFactory, req);
fail("Was expecting an ErrorDataDecoderException");
} catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
assertTrue(e.getCause() instanceof UnsupportedCharsetException);
} finally {
assertTrue(req.release());
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project netty by netty.
the class HttpPostRequestDecoderTest method testDecodeWithLanguageContentDispositionFieldParameters.
// https://github.com/netty/netty/pull/7265
@Test
public void testDecodeWithLanguageContentDispositionFieldParameters() throws Exception {
final String boundary = "74e78d11b0214bdcbc2f86491eeb4902";
String encoding = "utf-8";
String filename = "attached_файл.txt";
String language = "anything";
String filenameEncoded = URLEncoder.encode(filename, encoding);
final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename*=" + encoding + "'" + language + "'" + filenameEncoded + "\r\n" + "\r\n" + "foo\r\n" + "\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);
final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
assertFalse(decoder.getBodyHttpDatas().isEmpty());
InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0);
assertTrue(part1 instanceof FileUpload, "the item should be a FileUpload");
FileUpload fileUpload = (FileUpload) part1;
assertEquals(filename, fileUpload.getFilename(), "the filename should be decoded");
decoder.destroy();
assertTrue(req.release());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project netty by netty.
the class HttpPostMultiPartRequestDecoderTest method testDecodeFullHttpRequestWithInvalidCharset.
@Test
public void testDecodeFullHttpRequestWithInvalidCharset() {
FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
req.headers().set(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=--89421926422648 [; charset=UTF-8]");
try {
new HttpPostMultipartRequestDecoder(req);
fail("Was expecting an ErrorDataDecoderException");
} catch (HttpPostRequestDecoder.ErrorDataDecoderException expected) {
// expected
} finally {
assertTrue(req.release());
}
}
Aggregations