首页 > 解决方案 > Netty http/2 编解码器的 ReadTimeoutHandler

问题描述

有什么方法可以找出stream当前的 http/2 请求吗?我想给netty设置readtimeout,很明显的方法就是ReadTimeoutHandler。

在我的服务器初始化程序中,我这样做:

ch.pipeline().addLast(
      new ReadTimeoutHandler(10),  // here 
      ssl.newHandler(ch.alloc()),
      new MyHandler()
    )

然后在 MyHandler 中,我想向用户发送关于请求问题的 http/2 请求。

// class MyHandler

public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
   // send timeout response
}

但是为了发送 http/2 响应,我需要一个流 id。我有能力找出这个标识符吗?

标签: netty

解决方案


推荐阅读