Search in sources :

Example 86 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project netty by netty.

the class WebSocketServerInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
    pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH));
    pipeline.addLast(new WebSocketFrameHandler());
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) WebSocketServerCompressionHandler(io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) WebSocketServerProtocolHandler(io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 87 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project netty by netty.

the class WebSocketServerHandshaker13Test method testPerformOpeningHandshake0.

private static void testPerformOpeningHandshake0(boolean subProtocol) {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpObjectAggregator(42), new HttpResponseEncoder(), new HttpRequestDecoder());
    if (subProtocol) {
        testUpgrade0(ch, new WebSocketServerHandshaker13("ws://example.com/chat", "chat", false, Integer.MAX_VALUE, false));
    } else {
        testUpgrade0(ch, new WebSocketServerHandshaker13("ws://example.com/chat", null, false, Integer.MAX_VALUE, false));
    }
    assertFalse(ch.finish());
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Example 88 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project netty by netty.

the class WebSocketServerHandshaker08Test method testPerformOpeningHandshake0.

private static void testPerformOpeningHandshake0(boolean subProtocol) {
    EmbeddedChannel ch = new EmbeddedChannel(new HttpObjectAggregator(42), new HttpRequestDecoder(), new HttpResponseEncoder());
    FullHttpRequest req = new DefaultFullHttpRequest(HTTP_1_1, HttpMethod.GET, "/chat");
    req.headers().set(HttpHeaderNames.HOST, "server.example.com");
    req.headers().set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET);
    req.headers().set(HttpHeaderNames.CONNECTION, "Upgrade");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_KEY, "dGhlIHNhbXBsZSBub25jZQ==");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, "http://example.com");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, "chat, superchat");
    req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, "8");
    if (subProtocol) {
        new WebSocketServerHandshaker08("ws://example.com/chat", "chat", false, Integer.MAX_VALUE, false).handshake(ch, req);
    } else {
        new WebSocketServerHandshaker08("ws://example.com/chat", null, false, Integer.MAX_VALUE, false).handshake(ch, req);
    }
    ByteBuf resBuf = ch.readOutbound();
    EmbeddedChannel ch2 = new EmbeddedChannel(new HttpResponseDecoder());
    ch2.writeInbound(resBuf);
    HttpResponse res = ch2.readInbound();
    assertEquals("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT));
    if (subProtocol) {
        assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
    } else {
        assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
    }
    ReferenceCountUtil.release(res);
    req.release();
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpResponse(io.netty.handler.codec.http.HttpResponse) HttpResponseDecoder(io.netty.handler.codec.http.HttpResponseDecoder) ByteBuf(io.netty.buffer.ByteBuf)

Example 89 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project LogHub by fbacchella.

the class AbstractHttpServer method addHandlers.

@Override
public void addHandlers(ChannelPipeline p) {
    p.addLast(new HttpServerCodec());
    p.addLast(new HttpContentCompressor(9, 15, 8));
    p.addLast(new ChunkedWriteHandler());
    p.addLast(new HttpObjectAggregator(1048576));
    addModelHandlers(p);
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpContentCompressor(io.netty.handler.codec.http.HttpContentCompressor) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec)

Example 90 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project rest.li by linkedin.

the class TestRAPClientCodec method testDecodeException.

@Test
public void testDecodeException() {
    final EmbeddedChannel ch = new EmbeddedChannel(new HttpClientCodec(), new HttpObjectAggregator(65536), new RAPClientCodec());
    // When we received an invalid message, a decode exception should be thrown out of the
    // end of netty pipeline.
    String junk = "Not a HTTP message\r\n";
    try {
        ch.writeInbound(Unpooled.copiedBuffer(junk, CHARSET));
        Assert.fail("Should have thrown decode exception");
    } catch (Exception ex) {
    // expected.
    }
    ch.finish();
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteString(com.linkedin.data.ByteString) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) Test(org.testng.annotations.Test)

Aggregations

HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)95 ChannelPipeline (io.netty.channel.ChannelPipeline)60 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)34 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)29 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)28 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)25 SocketChannel (io.netty.channel.socket.SocketChannel)20 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)18 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)17 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)17 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)16 Bootstrap (io.netty.bootstrap.Bootstrap)13 Channel (io.netty.channel.Channel)12 EventLoopGroup (io.netty.channel.EventLoopGroup)11 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)11 SslHandler (io.netty.handler.ssl.SslHandler)11 HttpContentCompressor (io.netty.handler.codec.http.HttpContentCompressor)10 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)9 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)8 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)8