use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest 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.DefaultFullHttpRequest 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.DefaultFullHttpRequest in project netty by netty.
the class HttpPostRequestDecoderTest method testMultipartCodecWithCRasEndOfAttribute.
// See https://github.com/netty/netty/issues/2544
@Test
public void testMultipartCodecWithCRasEndOfAttribute() throws Exception {
final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";
// Force to use memory-based data.
final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
// Build test case
String extradata = "aaaa";
String[] datas = new String[5];
for (int i = 0; i < 4; i++) {
datas[i] = extradata;
for (int j = 0; j < i; j++) {
datas[i] += '\r';
}
}
for (int i = 0; i < 4; i++) {
final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost");
req.setDecoderResult(DecoderResult.SUCCESS);
req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
req.headers().add(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file" + i + "\"\r\n" + "Content-Type: image/gif\r\n" + "\r\n" + datas[i] + "\r\n" + "--" + boundary + "--\r\n";
req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8));
// Create decoder instance to test.
final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
assertFalse(decoder.getBodyHttpDatas().isEmpty());
// Check correctness: data size
InterfaceHttpData httpdata = decoder.getBodyHttpData("file" + i);
assertNotNull(httpdata);
Attribute attribute = (Attribute) httpdata;
byte[] datar = attribute.get();
assertNotNull(datar);
assertEquals(datas[i].getBytes(CharsetUtil.UTF_8).length, datar.length);
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 testMultipartRequestWithFileInvalidCharset.
@Test
public void testMultipartRequestWithFileInvalidCharset() 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 data = "asdf";
final String filename = "tmp;0.txt";
final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + "\"\r\n" + "Content-Type: image/gif; charset=ABCD\r\n" + "\r\n" + data + "\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 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());
}
Aggregations