类 io.netty.handler.codec.http2.Http2ServerUpgradeCodec 源码实例Demo

下面列出了怎么用 io.netty.handler.codec.http2.Http2ServerUpgradeCodec 的API类实例代码及写法,或者点击链接到github查看源代码。


@Override
public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
    if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
        return new Http2ServerUpgradeCodec(
                Http2MultiplexCodecBuilder.forServer(new HelloWorldHttp2Handler()).build());
    } 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;
    }
}
 

@Override
public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
    if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
        return new Http2ServerUpgradeCodec(
                Http2FrameCodecBuilder.forServer().build(), 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;
    }
}
 
源代码5 项目: reactor-netty   文件: HttpServerConfig.java

@Override
@Nullable
public HttpServerUpgradeHandler.UpgradeCodec newUpgradeCodec(CharSequence protocol) {
	if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
		return new Http2ServerUpgradeCodec(http2FrameCodec, new Http2MultiplexHandler(this));
	}
	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());
}
 
 同包方法