use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class HttpPostRequestDecoderTest method testDecodeFullHttpRequestWithUrlEncodedBody.
@Test
public void testDecodeFullHttpRequestWithUrlEncodedBody() throws Exception {
byte[] bodyBytes = "foo=bar&a=b&empty=&city=%3c%22new%22%20york%20city%3e&other_city=los+angeles".getBytes();
ByteBuf content = Unpooled.directBuffer(bodyBytes.length);
content.writeBytes(bodyBytes);
FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", content);
HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(req);
assertFalse(decoder.getBodyHttpDatas().isEmpty());
assertFalse(decoder.getBodyHttpDatas().isEmpty());
assertEquals(5, decoder.getBodyHttpDatas().size());
Attribute attr = (Attribute) decoder.getBodyHttpData("foo");
assertTrue(attr.getByteBuf().isDirect());
assertEquals("bar", attr.getValue());
attr = (Attribute) decoder.getBodyHttpData("a");
assertTrue(attr.getByteBuf().isDirect());
assertEquals("b", attr.getValue());
attr = (Attribute) decoder.getBodyHttpData("empty");
assertTrue(attr.getByteBuf().isDirect());
assertEquals("", attr.getValue());
attr = (Attribute) decoder.getBodyHttpData("city");
assertTrue(attr.getByteBuf().isDirect());
assertEquals("<\"new\" york city>", attr.getValue());
attr = (Attribute) decoder.getBodyHttpData("other_city");
assertTrue(attr.getByteBuf().isDirect());
assertEquals("los angeles", attr.getValue());
decoder.destroy();
assertTrue(req.release());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class HttpPostRequestDecoderTest method testDecodeFullHttpRequestWithUrlEncodedBodyWithBrokenHexByte0.
@Test
public void testDecodeFullHttpRequestWithUrlEncodedBodyWithBrokenHexByte0() {
byte[] bodyBytes = "foo=bar&a=b&empty=%&city=paris".getBytes();
ByteBuf content = Unpooled.directBuffer(bodyBytes.length);
content.writeBytes(bodyBytes);
FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", content);
try {
new HttpPostRequestDecoder(req);
fail("Was expecting an ErrorDataDecoderException");
} catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
assertEquals("Invalid hex byte at index '0' in string: '%'", e.getMessage());
} finally {
assertTrue(req.release());
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class HttpPostRequestDecoderTest method testDecodeFullHttpRequestWithUrlEncodedBodyWithInvalidHexNibbleLo.
@Test
public void testDecodeFullHttpRequestWithUrlEncodedBodyWithInvalidHexNibbleLo() {
byte[] bodyBytes = "foo=bar&a=b&empty=%2g&city=london".getBytes();
ByteBuf content = Unpooled.directBuffer(bodyBytes.length);
content.writeBytes(bodyBytes);
FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", content);
try {
new HttpPostRequestDecoder(req);
fail("Was expecting an ErrorDataDecoderException");
} catch (HttpPostRequestDecoder.ErrorDataDecoderException e) {
assertEquals("Invalid hex byte at index '0' in string: '%2g'", e.getMessage());
} finally {
assertTrue(req.release());
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest in project netty by netty.
the class HttpPostRequestDecoderTest method testMultipartRequest.
// https://github.com/netty/netty/issues/8575
@Test
public void testMultipartRequest() throws Exception {
String BOUNDARY = "01f136d9282f";
byte[] bodyBytes = ("--" + BOUNDARY + "\n" + "Content-Disposition: form-data; name=\"msg_id\"\n" + "\n" + "15200\n" + "--" + BOUNDARY + "\n" + "Content-Disposition: form-data; name=\"msg\"\n" + "\n" + "test message\n" + "--" + BOUNDARY + "--").getBytes();
ByteBuf byteBuf = Unpooled.directBuffer(bodyBytes.length);
byteBuf.writeBytes(bodyBytes);
FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.POST, "/up", byteBuf);
req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + BOUNDARY);
HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE), req, CharsetUtil.UTF_8);
assertTrue(decoder.isMultipart());
assertFalse(decoder.getBodyHttpDatas().isEmpty());
assertEquals(2, decoder.getBodyHttpDatas().size());
Attribute attrMsg = (Attribute) decoder.getBodyHttpData("msg");
assertTrue(attrMsg.getByteBuf().isDirect());
assertEquals("test message", attrMsg.getValue());
Attribute attrMsgId = (Attribute) decoder.getBodyHttpData("msg_id");
assertTrue(attrMsgId.getByteBuf().isDirect());
assertEquals("15200", attrMsgId.getValue());
decoder.destroy();
assertTrue(req.release());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest 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());
}
}
Aggregations