Netty 处理程序移除自身

Jos*_*son 5 java netty

我有一个 netty 身份验证处理程序,它查看传入的第一条消息 (HttpRequest),

如果请求获得授权,则在向上游发送消息之前,我让处理程序将自身从管道中删除。然而,下一条消息似乎仍然发送给处理程序。这是预期的吗?

使用 netty 4.14

public void channelRead(ChannelHandlerContext ctx, Object obj) throws Exception {
   if (!(obj instanceof HttpRequest)) {
    //Do not authenticate unknown object types.
    ReferenceCountUtil.release(obj);
    return;
  }

  HttpRequest httpRequest = (HttpRequest)obj;
  AuthenticatedInfo authenticatedInfo = Services.authenticationAuthority.authenticate(httpRequest, null);

  // check access
  if (authenticatedInfo.getMerchantId() == null) {
    sendUnauthorized(ctx);
    ReferenceCountUtil.release(obj);
  } else {
    ctx.pipeline().remove(this);
    ctx.fireChannelRead(httpRequest);
  }
}
Run Code Online (Sandbox Code Playgroud)