Class HAProxyMessageDecoder

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

    public class HAProxyMessageDecoder
    extends io.netty.handler.codec.ByteToMessageDecoder
    Decodes an HAProxy proxy protocol header
    See Also:
    Proxy Protocol Specification
    • Nested Class Summary

      • Nested classes/interfaces inherited from class io.netty.handler.codec.ByteToMessageDecoder

        io.netty.handler.codec.ByteToMessageDecoder.Cumulator
      • Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

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

      • Fields inherited from class io.netty.handler.codec.ByteToMessageDecoder

        COMPOSITE_CUMULATOR, MERGE_CUMULATOR
    • Constructor Summary

      Constructors 
      Constructor Description
      HAProxyMessageDecoder()
      Creates a new decoder with no additional data (TLV) restrictions, and should throw an exception as soon as we exceed maxLength.
      HAProxyMessageDecoder​(boolean failFast)
      Creates a new decoder with no additional data (TLV) restrictions, whether or not to throw an exception as soon as we exceed maxLength.
      HAProxyMessageDecoder​(int maxTlvSize)
      Creates a new decoder with restricted additional data (TLV) size, and should throw an exception as soon as we exceed maxLength.
      HAProxyMessageDecoder​(int maxTlvSize, boolean failFast)
      Creates a new decoder with restricted additional data (TLV) size, whether or not to throw an exception as soon as we exceed maxLength.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void channelRead​(io.netty.channel.ChannelHandlerContext ctx, Object msg)  
      protected void decode​(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out)  
      static io.netty.handler.codec.ProtocolDetectionResult<HAProxyProtocolVersion> detectProtocol​(io.netty.buffer.ByteBuf buffer)
      Returns the ProtocolDetectionResult for the given ByteBuf.
      boolean isSingleDecode()  
      • Methods inherited from class io.netty.handler.codec.ByteToMessageDecoder

        actualReadableBytes, callDecode, channelInactive, channelReadComplete, decodeLast, discardSomeReadBytes, handlerRemoved, handlerRemoved0, internalBuffer, setCumulator, setDiscardAfterReads, setSingleDecode, userEventTriggered
      • Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

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

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

        handlerAdded
    • Constructor Detail

      • HAProxyMessageDecoder

        public HAProxyMessageDecoder()
        Creates a new decoder with no additional data (TLV) restrictions, and should throw an exception as soon as we exceed maxLength.
      • HAProxyMessageDecoder

        public HAProxyMessageDecoder​(boolean failFast)
        Creates a new decoder with no additional data (TLV) restrictions, whether or not to throw an exception as soon as we exceed maxLength.
        Parameters:
        failFast - Whether or not to throw an exception as soon as we exceed maxLength
      • HAProxyMessageDecoder

        public HAProxyMessageDecoder​(int maxTlvSize)
        Creates a new decoder with restricted additional data (TLV) size, and should throw an exception as soon as we exceed maxLength.

        Note: limiting TLV size only affects processing of v2, binary headers. Also, as allowed by the 1.5 spec TLV data is currently ignored. For maximum performance it would be best to configure your upstream proxy host to NOT send TLV data and instantiate with a max TLV size of 0.

        Parameters:
        maxTlvSize - maximum number of bytes allowed for additional data (Type-Length-Value vectors) in a v2 header
      • HAProxyMessageDecoder

        public HAProxyMessageDecoder​(int maxTlvSize,
                                     boolean failFast)
        Creates a new decoder with restricted additional data (TLV) size, whether or not to throw an exception as soon as we exceed maxLength.
        Parameters:
        maxTlvSize - maximum number of bytes allowed for additional data (Type-Length-Value vectors) in a v2 header
        failFast - Whether or not to throw an exception as soon as we exceed maxLength
    • Method Detail

      • isSingleDecode

        public boolean isSingleDecode()
        Overrides:
        isSingleDecode in class io.netty.handler.codec.ByteToMessageDecoder
      • 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.handler.codec.ByteToMessageDecoder
        Throws:
        Exception
      • decode

        protected final void decode​(io.netty.channel.ChannelHandlerContext ctx,
                                    io.netty.buffer.ByteBuf in,
                                    List<Object> out)
                             throws Exception
        Specified by:
        decode in class io.netty.handler.codec.ByteToMessageDecoder
        Throws:
        Exception
      • detectProtocol

        public static io.netty.handler.codec.ProtocolDetectionResult<HAProxyProtocolVersion> detectProtocol​(io.netty.buffer.ByteBuf buffer)
        Returns the ProtocolDetectionResult for the given ByteBuf.