title: Netty - Skip the rest of the handlers in the pipeline
body: <p>I'm currently using Netty 4.0 if that matters but anyways..</p>
  
  <p>I have a handler written like so that I want to filter out requests depending on the URI:</p>
  
  <pre><code>public class URIFilterHandler extends SimpleChannelInboundHandler&lt;HttpRequest&gt; {
  
  public void channelRead0(ChannelHandlerContext ctx, HttpRequest req) {
      String uri = req.uri();
  
      if (uri.contains("abcde")) {
          HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NO_CONTENT);
          ctx.writeAndFlush(response);
          // HERE IS WHERE I WANT TO SKIP REST OF THE HANDLERS
  
      } else {
          ctx.fireChannelRead(req);
      }
  }
  }
  </code></pre>
  
  <p>And then here is my pipeline</p>
  
  <pre><code>public class ServerInitializer extends ChannelInitializer&lt;SocketChannel&gt; {
  
      @Override
      public void initChannel(SocketChannel ch) {
          ChannelPipeline p = ch.pipeline();
  
          p.addLast(new HttpRequestDecoder());
          p.addLast(new HttpResponseEncoder());
          p.addLast(new URIFilterHandler());
          p.addLast(new HttpObjectAggregator(1048576));
          p.addLast(new RequestHandler());
  
      }
  }
  </code></pre>
  
  <p>I tried the following, but it seemed to permanently remove these handlers from the pipeline and not just for the one request.</p>
  
  <pre><code>       ctx.pipeline().remove(HttpObjectAggregator.class);
         ctx.pipeline().remove(RequestHandler.class;)
  </code></pre>
  
  <p>I tried using ctx.channel().close() and ctx.fireChannelInactive() to no avail.  It seems to still pass the request onto the next handler (HttpObjectAggregator in this case).  I think it's possibly being due to the close() and fireChannelInactive() being asynchronous?</p>
  
  <p>EDIT: It seems the issue I was having was I was sending back a DefaultHttpResponse.  When I sent back a DefaultFullHttpResponse, the request never hangs.</p>