private void configureHttp1WithUpgrade(ChannelHandlerContext ctx) { final ChannelPipeline p = ctx.pipeline(); final HttpServerCodec http1codec = new HttpServerCodec( config.defaultMaxHttp1InitialLineLength(), config.defaultMaxHttp1HeaderSize(), config.defaultMaxHttp1ChunkSize()); String baseName = name; baseName = addAfter(p, baseName, http1codec); baseName = addAfter(p, baseName, new HttpServerUpgradeHandler( http1codec, protocol -> { if (!AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) { return null; } return new Http2ServerUpgradeCodec( newHttp2ConnectionHandler(p)); }, UPGRADE_REQUEST_MAX_LENGTH)); addAfter(p, baseName, new Http1RequestDecoder(config, ctx.channel(), SCHEME_HTTP)); }
@Override public UpgradeCodec newUpgradeCodec(CharSequence protocol) { if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) { return new Http2ServerUpgradeCodec(new Http2MultiplexCodec(true, new HelloWorldHttp2Handler())); } else { return null; } }
@Override public UpgradeCodec newUpgradeCodec(CharSequence protocol) { if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) { return new Http2ServerUpgradeCodec(new HelloWorldHttp2HandlerBuilder().build()); } else { return null; } }
/** * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2. */ private static void configureClearText(SocketChannel ch) { HttpServerCodec sourceCodec = new HttpServerCodec(); HelloWorldHttp2Handler http2Handler = new HelloWorldHttp2Handler(); HttpServerUpgradeHandler.UpgradeCodec upgradeCodec = new Http2ServerUpgradeCodec(http2Handler); HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(sourceCodec, Collections.singletonList(upgradeCodec), 65536); ch.pipeline().addLast(sourceCodec); ch.pipeline().addLast(upgradeHandler); ch.pipeline().addLast(new UserEventLogger()); }
private void h2cOrHttp1(final ChannelHandlerContext ctx) { ChannelPipeline p = ctx.pipeline(); HttpServerCodec http1codec = http1Codec(); String baseName = name; baseName = addAfter(p, baseName, "codec", http1codec); baseName = addAfter(p, baseName, "h2upgrade", new HttpServerUpgradeHandler(http1codec, protocol -> { if (!AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) { return null; } return new Http2ServerUpgradeCodec(newHttp2ConnectionHandler(p)); }, maxContentLength)); }