proxyproto

package
v1.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger = log.Default()

Functions

func ListenAndServe

func ListenAndServe(srv *http.Server) error

ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections.

func ListenAndServeTLS

func ListenAndServeTLS(srv *http.Server, certFile, keyFile string) error

ListenAndServeTLS listens on the TCP network address srv.Addr and then calls ServeTLS to handle requests on incoming TLS connections.

func NewConn

func NewConn(nc net.Conn) net.Conn

NewConn wraps a net.Conn and returns a new proxyproto.Conn that reads the PROXY protocol header from the connection. If the connection is not a PROXY protocol connection, it returns the original connection.

func NewListener

func NewListener(l net.Listener) net.Listener

NewListener wraps a net.Listener and returns a new net.Listener that returns a proxyproto.Conn when Accept is called.

It is used to handle PROXY protocol connections.

Types

type Command

type Command byte

Command represents the command in proxy protocol v2. Command doesn't exist in v1 but it should be set since other parts of this library may rely on it for determining connection details.

const (
	// LOCAL represents the LOCAL command in v2,
	// in which case no address information is expected.
	LOCAL Command = '\x20'
	// PROXY represents the PROXY command in v2,
	// in which case valid local/remote address and port information is expected.
	PROXY Command = '\x21'
)
type Header struct {
	// LocalAddr is the ip address of the party that initiated the connection
	LocalAddr net.Addr
	// RemoteAddr is the ip address the remote party connected to; aka the address
	// the proxy was listening for connections on.
	RemoteAddr net.Addr
	// The version of the proxy protocol parsed
	Version int

	// V2
	Command  Command
	Protocol Protocol
	// The unparsed TLVs (Type-Length-Value) that were appended to the end of
	// the v2 proto proxy header.
	RawTLVs []byte
}

Header represents the structure of the proxy protocol header. It holds information about the connection, such as local and remote addresses, the protocol version, and any additional TLVs (Type-Length-Value) in the v2 protocol.

type Protocol

type Protocol byte

Protocol represents address family and transport protocol.

const (
	TCPv4 Protocol = '\x11'
	UDPv4 Protocol = '\x12'
	TCPv6 Protocol = '\x21'
	UDPv6 Protocol = '\x22'
)

func (Protocol) IsDatagram

func (ap Protocol) IsDatagram() bool

IsDatagram returns true if the transport protocol is UDP or DGRAM (SOCK_DGRAM), false otherwise.

func (Protocol) IsIPv4

func (ap Protocol) IsIPv4() bool

IsIPv4 returns true if the address family is IPv4 (AF_INET4), false otherwise.

func (Protocol) IsIPv6

func (ap Protocol) IsIPv6() bool

IsIPv6 returns true if the address family is IPv6 (AF_INET6), false otherwise.

func (Protocol) IsStream

func (ap Protocol) IsStream() bool

IsStream returns true if the transport protocol is TCP or STREAM (SOCK_STREAM), false otherwise.

func (Protocol) IsUnix

func (ap Protocol) IsUnix() bool

IsUnix returns true if the address family is UNIX (AF_UNIX), false otherwise.

func (Protocol) IsUnspec

func (ap Protocol) IsUnspec() bool

IsUnspec returns true if the transport protocol or address family is unspecified, false otherwise.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL