Class HttpServerKeepAliveHandler

  • All Implemented Interfaces:
    io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

    public class HttpServerKeepAliveHandler
    extends io.netty.channel.ChannelDuplexHandler
    HttpServerKeepAliveHandler helps close persistent connections when appropriate.

    The server channel is expected to set the proper 'Connection' header if it can handle persistent connections. HttpServerKeepAliveHandler will automatically close the channel for any LastHttpContent that corresponds to a client request for closing the connection, or if the HttpResponse associated with that LastHttpContent requested closing the connection or didn't have a self defined message length.

    Since HttpServerKeepAliveHandler expects HttpObjects it should be added after HttpServerCodec but before any other handlers that might send a HttpResponse.

      ChannelPipeline p = ...;
      ...
      p.addLast("serverCodec", new HttpServerCodec());
      p.addLast("httpKeepAlive", new HttpServerKeepAliveHandler());
      p.addLast("aggregator", new HttpObjectAggregator(1048576));
      ...
      p.addLast("handler", new HttpRequestHandler());
      
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

        io.netty.channel.ChannelHandler.Sharable
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void channelRead​(io.netty.channel.ChannelHandlerContext ctx, Object msg)  
      void write​(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)  
      • Methods inherited from class io.netty.channel.ChannelDuplexHandler

        bind, close, connect, deregister, disconnect, flush, read
      • Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

        channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
      • Methods inherited from class io.netty.channel.ChannelHandlerAdapter

        ensureNotSharable, handlerAdded, handlerRemoved, isSharable
      • Methods inherited from interface io.netty.channel.ChannelHandler

        handlerAdded, handlerRemoved
    • Constructor Detail

      • HttpServerKeepAliveHandler

        public HttpServerKeepAliveHandler()
    • Method Detail

      • channelRead

        public void channelRead​(io.netty.channel.ChannelHandlerContext ctx,
                                Object msg)
                         throws Exception
        Specified by:
        channelRead in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • write

        public void write​(io.netty.channel.ChannelHandlerContext ctx,
                          Object msg,
                          io.netty.channel.ChannelPromise promise)
                   throws Exception
        Specified by:
        write in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        write in class io.netty.channel.ChannelDuplexHandler
        Throws:
        Exception