Package io.netty.handler.codec.haproxy
Class HAProxyMessageDecoder
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.ByteToMessageDecoder
-
- io.netty.handler.codec.haproxy.HAProxyMessageDecoder
-
- All Implemented Interfaces:
ChannelHandler
,ChannelInboundHandler
public class HAProxyMessageDecoder extends 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
ByteToMessageDecoder.Cumulator
-
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
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(ChannelHandlerContext ctx, java.lang.Object msg)
CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
.protected void
decode(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out)
Decode the from oneByteBuf
to an other.static ProtocolDetectionResult<HAProxyProtocolVersion>
detectProtocol(ByteBuf buffer)
Returns theProtocolDetectionResult
for the givenByteBuf
.boolean
isSingleDecode()
Iftrue
then only one message is decoded on eachByteToMessageDecoder.channelRead(ChannelHandlerContext, Object)
call.-
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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
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 headerfailFast
- Whether or not to throw an exception as soon as we exceed maxLength
-
-
Method Detail
-
isSingleDecode
public boolean isSingleDecode()
Description copied from class:ByteToMessageDecoder
Iftrue
then only one message is decoded on eachByteToMessageDecoder.channelRead(ChannelHandlerContext, Object)
call. Default isfalse
as this has performance impacts.- Overrides:
isSingleDecode
in classByteToMessageDecoder
-
channelRead
public void channelRead(ChannelHandlerContext ctx, java.lang.Object msg) throws java.lang.Exception
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelRead
in interfaceChannelInboundHandler
- Overrides:
channelRead
in classByteToMessageDecoder
- Throws:
java.lang.Exception
-
decode
protected final void decode(ChannelHandlerContext ctx, ByteBuf in, java.util.List<java.lang.Object> out) throws java.lang.Exception
Description copied from class:ByteToMessageDecoder
Decode the from oneByteBuf
to an other. This method will be called till either the inputByteBuf
has nothing to read when return from this method or till nothing was read from the inputByteBuf
.- Specified by:
decode
in classByteToMessageDecoder
- Parameters:
ctx
- theChannelHandlerContext
which thisByteToMessageDecoder
belongs toin
- theByteBuf
from which to read dataout
- theList
to which decoded messages should be added- Throws:
java.lang.Exception
- is thrown if an error occurs
-
detectProtocol
public static ProtocolDetectionResult<HAProxyProtocolVersion> detectProtocol(ByteBuf buffer)
Returns theProtocolDetectionResult
for the givenByteBuf
.
-
-