Top Description Fields Constructors Methods
io.netty.contrib.handler.codec.haproxy

public final Class HAProxyMessage

extends Object
implements Resource<HAProxyMessage>
Class Inheritance
All Implemented Interfaces
io.netty5.util.Resource, java.lang.AutoCloseable
Static Imports
java.util.Objects.requireNonNull

Message container for decoded HAProxy proxy protocol parameters

Field Summary

Modifier and TypeField and Description
private final HAProxyCommand
private final String
private final int
private final HAProxyProtocolVersion
private final HAProxyProxiedProtocol
private final String
private final int
private final List<HAProxyTLV>

Constructor Summary

AccessConstructor and Description
private
HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, String sourcePort, String destinationPort)

Creates a new instance

public
HAProxyMessage(HAProxyProtocolVersion
the protocol version.
protocolVersion
,
HAProxyCommand
the command.
command
,
HAProxyProxiedProtocol
the protocol containing the address family and transport protocol.
proxiedProtocol
,
String
the source address.
sourceAddress
,
String
the destination address.
destinationAddress
,
int
the source port. This value must be 0 for unix, unspec addresses.
sourcePort
,
int
the destination port. This value must be 0 for unix, unspec addresses.
destinationPort
)

Creates a new instance of HAProxyMessage.

public
HAProxyMessage(HAProxyProtocolVersion
the protocol version.
protocolVersion
,
HAProxyCommand
the command.
command
,
HAProxyProxiedProtocol
the protocol containing the address family and transport protocol.
proxiedProtocol
,
String
the source address.
sourceAddress
,
String
the destination address.
destinationAddress
,
int
the source port. This value must be 0 for unix, unspec addresses.
sourcePort
,
int
the destination port. This value must be 0 for unix, unspec addresses.
destinationPort
,
List<? extends HAProxyTLV>
the list of tlvs.
tlvs
)

Creates a new instance of HAProxyMessage.

Method Summary

Modifier and TypeMethod and Description
private static void
checkAddress(String
human-readable address
address
,
HAProxyProxiedProtocol.AddressFamily
the AddressFamily to check the address against
addrFamily
)

Validate an address (IPv4, IPv6, Unix Socket)

private static void
checkPort(int
the UDP/TCP port
port
,
HAProxyProxiedProtocol.AddressFamily addrFamily)

Validate the port depending on the addrFamily.

public void
close()

Implements io.netty5.util.Resource.close.

Close the resource, making it inaccessible.
public HAProxyCommand
command()

Returns the HAProxyCommand of this HAProxyMessage.

pack-priv static HAProxyMessage

Returns:

HAProxyMessage instance
decodeHeader
(Buffer
a version 2 proxy protocol header
header
)

Decodes a version 2, binary proxy protocol header.

pack-priv static HAProxyMessage

Returns:

HAProxyMessage instance
decodeHeader
(String
a version 1 proxy protocol header
header
)

Decodes a version 1, human-readable proxy protocol header.

public String
destinationAddress()

Returns the human-readable destination address of this HAProxyMessage.

public int
destinationPort()

Returns the UDP/TCP destination port of this HAProxyMessage.

private static String

Returns:

string representation of the ip address
ipBytesToString
(Buffer
buffer containing ip address bytes
header
,
int
number of bytes to read (4 bytes for IPv4, 16 bytes for IPv6)
addressLen
)

Convert ip address bytes to string representation

public boolean
isAccessible()

Implements io.netty5.util.Resource.isAccessible.

Check if this object is accessible.
private static int

Returns:

port as an integer
portStringToInt
(String
the port
value
)

Convert port to integer

public HAProxyProtocolVersion
public HAProxyProxiedProtocol
private static HAProxyTLV
readNextTLV(final Buffer header)

private static List<HAProxyTLV>
readTlvs(final Buffer header)

public Send<HAProxyMessage>
send()

Implements io.netty5.util.Resource.send.

Send this object instance to another Thread, transferring the ownership to the recipient.
public String
sourceAddress()

Returns the human-readable source address of this HAProxyMessage or null if HAProxy performs health check with send-proxy-v2.

public int
sourcePort()

Returns the UDP/TCP source port of this HAProxyMessage.

pack-priv int
public List<HAProxyTLV>
tlvs()

Returns a list of HAProxyTLV or an empty list if no TLVs are present.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private static HAProxyMessage
unknownMsg(HAProxyProtocolVersion version, HAProxyCommand command)

Proxy protocol message for 'UNKNOWN' proxied protocols.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

commandback to summary
private final HAProxyCommand command
destinationAddressback to summary
private final String destinationAddress
destinationPortback to summary
private final int destinationPort
protocolVersionback to summary
private final HAProxyProtocolVersion protocolVersion
proxiedProtocolback to summary
private final HAProxyProxiedProtocol proxiedProtocol
sourceAddressback to summary
private final String sourceAddress
sourcePortback to summary
private final int sourcePort
tlvsback to summary
private final List<HAProxyTLV> tlvs

Constructor Detail

HAProxyMessageback to summary
private HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, String sourcePort, String destinationPort)

Creates a new instance

HAProxyMessageback to summary
public HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, int sourcePort, int destinationPort)

Creates a new instance of HAProxyMessage.

Parameters
protocolVersion:HAProxyProtocolVersion

the protocol version.

command:HAProxyCommand

the command.

proxiedProtocol:HAProxyProxiedProtocol

the protocol containing the address family and transport protocol.

sourceAddress:String

the source address.

destinationAddress:String

the destination address.

sourcePort:int

the source port. This value must be 0 for unix, unspec addresses.

destinationPort:int

the destination port. This value must be 0 for unix, unspec addresses.

HAProxyMessageback to summary
public HAProxyMessage(HAProxyProtocolVersion protocolVersion, HAProxyCommand command, HAProxyProxiedProtocol proxiedProtocol, String sourceAddress, String destinationAddress, int sourcePort, int destinationPort, List<? extends HAProxyTLV> tlvs)

Creates a new instance of HAProxyMessage.

Parameters
protocolVersion:HAProxyProtocolVersion

the protocol version.

command:HAProxyCommand

the command.

proxiedProtocol:HAProxyProxiedProtocol

the protocol containing the address family and transport protocol.

sourceAddress:String

the source address.

destinationAddress:String

the destination address.

sourcePort:int

the source port. This value must be 0 for unix, unspec addresses.

destinationPort:int

the destination port. This value must be 0 for unix, unspec addresses.

tlvs:List<? extends HAProxyTLV>

the list of tlvs.

Method Detail

checkAddressback to summary
private static void checkAddress(String address, HAProxyProxiedProtocol.AddressFamily addrFamily)

Validate an address (IPv4, IPv6, Unix Socket)

Parameters
address:String

human-readable address

addrFamily:HAProxyProxiedProtocol.AddressFamily

the AddressFamily to check the address against

Exceptions
IllegalArgumentException:
if the address is invalid
checkPortback to summary
private static void checkPort(int port, HAProxyProxiedProtocol.AddressFamily addrFamily)

Validate the port depending on the addrFamily.

Parameters
port:int

the UDP/TCP port

Exceptions
IllegalArgumentException:
if the port is out of range (0-65535 inclusive)
closeback to summary
public void close()

Implements io.netty5.util.Resource.close.

Doc from io.netty5.util.Resource.close.

Close the resource, making it inaccessible.

Note, this method is not thread-safe unless otherwise specified.

Annotations
@Override
commandback to summary
public HAProxyCommand command()

Returns the HAProxyCommand of this HAProxyMessage.

decodeHeaderback to summary
pack-priv static HAProxyMessage decodeHeader(Buffer header)

Decodes a version 2, binary proxy protocol header.

Parameters
header:Buffer

a version 2 proxy protocol header

Returns:HAProxyMessage

HAProxyMessage instance

Exceptions
HAProxyProtocolException:
if any portion of the header is invalid
decodeHeaderback to summary
pack-priv static HAProxyMessage decodeHeader(String header)

Decodes a version 1, human-readable proxy protocol header.

Parameters
header:String

a version 1 proxy protocol header

Returns:HAProxyMessage

HAProxyMessage instance

Exceptions
HAProxyProtocolException:
if any portion of the header is invalid
destinationAddressback to summary
public String destinationAddress()

Returns the human-readable destination address of this HAProxyMessage.

destinationPortback to summary
public int destinationPort()

Returns the UDP/TCP destination port of this HAProxyMessage.

ipBytesToStringback to summary
private static String ipBytesToString(Buffer header, int addressLen)

Convert ip address bytes to string representation

Parameters
header:Buffer

buffer containing ip address bytes

addressLen:int

number of bytes to read (4 bytes for IPv4, 16 bytes for IPv6)

Returns:String

string representation of the ip address

isAccessibleback to summary
public boolean isAccessible()

Implements io.netty5.util.Resource.isAccessible.

Doc from io.netty5.util.Resource.isAccessible.

Check if this object is accessible.

Returns:boolean

true if this object is still valid and can be accessed, otherwise false if, for instance, this object has been dropped/deallocated, or been sent elsewhere.

Annotations
@Override
portStringToIntback to summary
private static int portStringToInt(String value)

Convert port to integer

Parameters
value:String

the port

Returns:int

port as an integer

Exceptions
IllegalArgumentException:
if port is not a valid integer
protocolVersionback to summary
public HAProxyProtocolVersion protocolVersion()

Returns the HAProxyProtocolVersion of this HAProxyMessage.

proxiedProtocolback to summary
public HAProxyProxiedProtocol proxiedProtocol()

Returns the HAProxyProxiedProtocol of this HAProxyMessage.

readNextTLVback to summary
private static HAProxyTLV readNextTLV(final Buffer header)
readTlvsback to summary
private static List<HAProxyTLV> readTlvs(final Buffer header)
sendback to summary
public Send<HAProxyMessage> send()

Implements io.netty5.util.Resource.send.

Doc from io.netty5.util.Resource.send.

Send this object instance to another Thread, transferring the ownership to the recipient.

The object must be in a state where it can be sent, which includes at least being accessible.

When sent, this instance will immediately become inaccessible, as if by closing it. All attempts at accessing an object that has been sent, even if that object has not yet been received, should cause an exception to be thrown.

Calling close() on an object that has been sent will have no effect, so this method is safe to call within a try-with-resources statement.

Annotations
@Override
sourceAddressback to summary
public String sourceAddress()

Returns the human-readable source address of this HAProxyMessage or null if HAProxy performs health check with send-proxy-v2.

sourcePortback to summary
public int sourcePort()

Returns the UDP/TCP source port of this HAProxyMessage.

tlvNumBytesback to summary
pack-priv int tlvNumBytes()
tlvsback to summary
public List<HAProxyTLV> tlvs()

Returns a list of HAProxyTLV or an empty list if no TLVs are present.

TLVs are only available for the Proxy Protocol V2

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
unknownMsgback to summary
private static HAProxyMessage unknownMsg(HAProxyProtocolVersion version, HAProxyCommand command)

Proxy protocol message for 'UNKNOWN' proxied protocols. Per spec, when the proxied protocol is 'UNKNOWN' we must discard all other header values.