Class ProxyProtocolOriginalDestinationHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler
proxy_protocol on).
Placement: This handler must be added FIRST in the transparent-proxy pipeline
(before TransparentProxyHandler and the port-unification handler). It inspects
the first inbound bytes and dispatches on the first byte:
0x0D— candidate PROXY v2 (binary): the 12-byte v2 signature begins with0x0D, which can never start a v1 header, an HTTP request, or a TLS record.'P'— candidate PROXY v1 (text): the"PROXY "ASCII signature.- anything else — not a PROXY header; pass through unchanged.
REMOTE_SOCKET /
PROXYING / TRANSPARENT_ORIGINAL_DST_RESOLVED channel attributes, and removes
itself from the pipeline.
PROXY v1 format (HAProxy spec):
PROXY TCP4 <srcIP> <dstIP> <srcPort> <dstPort>\r\n PROXY TCP6 <srcIP> <dstIP> <srcPort> <dstPort>\r\n PROXY UNKNOWN\r\nMaximum v1 header length is 107 bytes (per the spec). The handler enforces this bound.
PROXY v2 format (HAProxy spec): a 12-byte binary signature
(0D 0A 0D 0A 00 0D 0A 51 55 49 54 0A) followed by a 4-byte prefix
(version+command, address-family+transport, and a big-endian uint16 address-block length),
then the address block. For the PROXY command (LOCAL is a health-check with no address) and
the INET / INET6 families, the destination address and port are extracted. UNIX-socket and
unsupported families are consumed but leave destination resolution to downstream strategies.
Fail-safe: Malformed, oversized, or unrecognised headers cause the handler to remove itself and pass through all bytes unchanged, logging a warning. The connection continues as if no PROXY header was present.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx) Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded
-
Constructor Details
-
ProxyProtocolOriginalDestinationHandler
-
-
Method Details
-
channelRead
- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) - Specified by:
handlerRemovedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerRemovedin classio.netty.channel.ChannelHandlerAdapter
-