Search in sources :

Example 16 with HttpServerCodec

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

the class HttpProxyServer method configure.

@Override
protected void configure(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    switch(testMode) {
        case INTERMEDIARY:
            p.addLast(new HttpServerCodec());
            p.addLast(new HttpObjectAggregator(1));
            p.addLast(new HttpIntermediaryHandler());
            break;
        case TERMINAL:
            p.addLast(new HttpServerCodec());
            p.addLast(new HttpObjectAggregator(1));
            p.addLast(new HttpTerminalHandler());
            break;
        case UNRESPONSIVE:
            p.addLast(UnresponsiveHandler.INSTANCE);
            break;
    }
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 17 with HttpServerCodec

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

the class Http2ServerInitializer method configureClearText.

/**
 * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.0
 */
private void configureClearText(SocketChannel ch) {
    final ChannelPipeline p = ch.pipeline();
    final HttpServerCodec sourceCodec = new HttpServerCodec();
    final HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory);
    final CleartextHttp2ServerUpgradeHandler cleartextHttp2ServerUpgradeHandler = new CleartextHttp2ServerUpgradeHandler(sourceCodec, upgradeHandler, new HelloWorldHttp2HandlerBuilder().build());
    p.addLast(cleartextHttp2ServerUpgradeHandler);
    p.addLast(new SimpleChannelInboundHandler<HttpMessage>() {

        @Override
        protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception {
            // If this handler is hit then no upgrade has been attempted and the client is just talking HTTP.
            System.err.println("Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)");
            ChannelPipeline pipeline = ctx.pipeline();
            ChannelHandlerContext thisCtx = pipeline.context(this);
            pipeline.addAfter(thisCtx.name(), null, new HelloWorldHttp1Handler("Direct. No Upgrade Attempted."));
            pipeline.replace(this, null, new HttpObjectAggregator(maxHttpContentLength));
            ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
        }
    });
    p.addLast(new UserEventLogger());
}
Also used : CleartextHttp2ServerUpgradeHandler(io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpServerUpgradeHandler(io.netty.handler.codec.http.HttpServerUpgradeHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) HttpMessage(io.netty.handler.codec.http.HttpMessage)

Example 18 with HttpServerCodec

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

the class HttpStaticFileServerInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    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 ChunkedWriteHandler());
    pipeline.addLast(new HttpStaticFileServerHandler());
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 19 with HttpServerCodec

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

the class WebSocketServerProtocolHandlerTest method createServer.

private EmbeddedChannel createServer(ChannelHandler... handlers) throws Exception {
    WebSocketServerProtocolConfig serverConfig = WebSocketServerProtocolConfig.newBuilder().websocketPath("/test").dropPongFrames(false).build();
    EmbeddedChannel ch = new EmbeddedChannel(false, false, new HttpServerCodec(), new HttpObjectAggregator(8192), new WebSocketServerProtocolHandler(serverConfig));
    ch.pipeline().addLast(handlers);
    ch.register();
    return ch;
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec)

Example 20 with HttpServerCodec

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec 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 WebSocketServerHandler());
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)54 ChannelPipeline (io.netty.channel.ChannelPipeline)35 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)30 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)11 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)11 HttpServerUpgradeHandler (io.netty.handler.codec.http.HttpServerUpgradeHandler)10 Test (org.junit.Test)9 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)8 Channel (io.netty.channel.Channel)7 ChannelHandler (io.netty.channel.ChannelHandler)7 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)7 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)7 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)6 ChannelHandlerAdapter (io.netty.channel.ChannelHandlerAdapter)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)6 LineBasedFrameDecoder (io.netty.handler.codec.LineBasedFrameDecoder)6 WebSocketServerProtocolHandler (io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler)6 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)6 SocketChannel (io.netty.channel.socket.SocketChannel)4 HttpContentCompressor (io.netty.handler.codec.http.HttpContentCompressor)4