Search in sources :

Example 1 with HelloWorldHttp1Handler

use of io.netty.example.http2.helloworld.server.HelloWorldHttp1Handler 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();
    p.addLast(sourceCodec);
    p.addLast(new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory));
    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 : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HelloWorldHttp1Handler(io.netty.example.http2.helloworld.server.HelloWorldHttp1Handler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpServerUpgradeHandler(io.netty.handler.codec.http.HttpServerUpgradeHandler) HttpMessage(io.netty.handler.codec.http.HttpMessage) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 HelloWorldHttp1Handler (io.netty.example.http2.helloworld.server.HelloWorldHttp1Handler)1 HttpMessage (io.netty.handler.codec.http.HttpMessage)1 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)1 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)1 HttpServerUpgradeHandler (io.netty.handler.codec.http.HttpServerUpgradeHandler)1