• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java HttpServerUpgradeHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.netty.handler.codec.http.HttpServerUpgradeHandler的典型用法代码示例。如果您正苦于以下问题:Java HttpServerUpgradeHandler类的具体用法?Java HttpServerUpgradeHandler怎么用?Java HttpServerUpgradeHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HttpServerUpgradeHandler类属于io.netty.handler.codec.http包,在下文中一共展示了HttpServerUpgradeHandler类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: configureHttp1WithUpgrade

import io.netty.handler.codec.http.HttpServerUpgradeHandler; //导入依赖的package包/类
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));
}
 
开发者ID:line,项目名称:armeria,代码行数:24,代码来源:HttpServerPipelineConfigurator.java


示例2: userEventTriggered

import io.netty.handler.codec.http.HttpServerUpgradeHandler; //导入依赖的package包/类
@Override
public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt)
    throws Exception {
  // Idle timeout
  if (evt instanceof IdleStateEvent) {
    log.debug("idle timeout: {}", ctx);
    ctx.close();
  } else if (evt instanceof HttpServerUpgradeHandler.UpgradeEvent) {
    // Write an HTTP/2 response to the upgrade request
    FullHttpRequest req = ((HttpServerUpgradeHandler.UpgradeEvent) evt).upgradeRequest();
    req.headers().set(STREAM_ID, req.headers().get(STREAM_ID, "1"));
    channelRead0(ctx, req);
  } else {
    super.userEventTriggered(ctx, evt);
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:17,代码来源:NettyHandler.java


示例3: userEventTriggered

import io.netty.handler.codec.http.HttpServerUpgradeHandler; //导入依赖的package包/类
/**
 * Handles the cleartext HTTP upgrade event. If an upgrade occurred, sends a simple response via HTTP/2
 * on stream 1 (the stream specifically reserved for cleartext HTTP upgrade).
 */
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof HttpServerUpgradeHandler.UpgradeEvent) {
        // Write an HTTP/2 response to the upgrade request
        Http2Headers headers =
                new DefaultHttp2Headers().status(OK.codeAsText())
                .set(new AsciiString(UPGRADE_RESPONSE_HEADER), new AsciiString("true"));
        encoder().writeHeaders(ctx, 1, headers, 0, true, ctx.newPromise());
    }
    super.userEventTriggered(ctx, evt);
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:16,代码来源:HelloWorldHttp2Handler.java


示例4: configureClearText

import io.netty.handler.codec.http.HttpServerUpgradeHandler; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:duchien85,项目名称:netty-cookbook,代码行数:14,代码来源:Http2ServerInitializer.java


示例5: userEventTriggered

import io.netty.handler.codec.http.HttpServerUpgradeHandler; //导入依赖的package包/类
/**
 * This method handles the cleartext HTTP upgrade event. If an upgrade occurred, sends a simple response via HTTP/2
 * on stream 1 (the stream specifically reserved for cleartext HTTP upgrade).
 *
 * @param ctx Channel context
 * @param evt Event
 * @throws Exception Throws when user event trigger has an error
 */
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof HttpServerUpgradeHandler.UpgradeEvent) {
        // Write an HTTP/2 response to the upgrade request
        Http2Headers headers =
                new DefaultHttp2Headers().status(OK.codeAsText())
                        .set(new AsciiString(Constants.UPGRADE_RESPONSE_HEADER), new AsciiString("true"));
        encoder().writeHeaders(ctx, 1, headers, 0, true, ctx.newPromise());
    }
    super.userEventTriggered(ctx, evt);
}
 
开发者ID:wso2,项目名称:carbon-transports,代码行数:20,代码来源:HTTP2SourceHandler.java


示例6: h2cOrHttp1

import io.netty.handler.codec.http.HttpServerUpgradeHandler; //导入依赖的package包/类
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));
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:15,代码来源:NettyPipeline.java



注:本文中的io.netty.handler.codec.http.HttpServerUpgradeHandler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RegionServerReportRequest类代码示例发布时间:2022-05-22
下一篇:
Java PropertySheetTableModel类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap