Class HAProxyMessageDecoder

All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler

public class HAProxyMessageDecoder extends ByteToMessageDecoder
Decodes an HAProxy proxy protocol header
See Also:
  • Field Details

    • V1_MAX_LENGTH

      private static final int V1_MAX_LENGTH
      Maximum possible length of a v1 proxy protocol header per spec
      See Also:
    • V2_MAX_LENGTH

      private static final int V2_MAX_LENGTH
      Maximum possible length of a v2 proxy protocol header (fixed 16 bytes + max unsigned short)
      See Also:
    • V2_MIN_LENGTH

      private static final int V2_MIN_LENGTH
      Minimum possible length of a fully functioning v2 proxy protocol header (fixed 16 bytes + v2 address info space)
      See Also:
    • V2_MAX_TLV

      private static final int V2_MAX_TLV
      Maximum possible length for v2 additional TLV data (max unsigned short - max v2 address info space)
      See Also:
    • BINARY_PREFIX_LENGTH

      private static final int BINARY_PREFIX_LENGTH
      Binary header prefix length
    • DETECTION_RESULT_V1

      private static final ProtocolDetectionResult<HAProxyProtocolVersion> DETECTION_RESULT_V1
    • DETECTION_RESULT_V2

      private static final ProtocolDetectionResult<HAProxyProtocolVersion> DETECTION_RESULT_V2
    • headerExtractor

      private HAProxyMessageDecoder.HeaderExtractor headerExtractor
      Used to extract a header frame out of the ByteBuf and return it.
    • discarding

      private boolean discarding
      true if we're discarding input because we're already over maxLength
    • discardedBytes

      private int discardedBytes
      Number of discarded bytes
    • failFast

      private final boolean failFast
      Whether or not to throw an exception as soon as we exceed maxLength.
    • finished

      private boolean finished
      true if we're finished decoding the proxy protocol header
    • version

      private int version
      Protocol specification version
    • v2MaxHeaderSize

      private final int v2MaxHeaderSize
      The latest v2 spec (2014/05/18) allows for additional data to be sent in the proxy protocol header beyond the address information block so now we need a configurable max header size
  • Constructor Details

    • 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 Details