Search in sources :

Example 66 with DefaultFullHttpRequest

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());
    }
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest)

Example 67 with DefaultFullHttpRequest

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());
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Test(org.junit.jupiter.api.Test)

Example 68 with DefaultFullHttpRequest

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());
    }
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) Test(org.junit.jupiter.api.Test)

Example 69 with DefaultFullHttpRequest

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());
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Test(org.junit.jupiter.api.Test)

Example 70 with DefaultFullHttpRequest

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());
    }
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)215 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)117 Test (org.junit.jupiter.api.Test)72 Test (org.junit.Test)61 ByteBuf (io.netty.buffer.ByteBuf)56 HttpRequest (io.netty.handler.codec.http.HttpRequest)47 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)43 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)40 AsciiString (io.netty.util.AsciiString)30 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)23 Channel (io.netty.channel.Channel)20 ChannelPromise (io.netty.channel.ChannelPromise)19 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)18 IOException (java.io.IOException)17 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)15 HttpResponse (io.netty.handler.codec.http.HttpResponse)15 URI (java.net.URI)15 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)14 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)13 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)12