proxyproto

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MPL-2.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	V1Identifier = []byte("PROXY ")
	V2Identifier = []byte("\r\n\r\n\x00\r\nQUIT\n")
)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	net.Conn
	// contains filtered or unexported fields
}

Conn wraps a net.Conn and provides access to the proxy protocol header. If the header is not present or cannot be read within the timeout, the connection is closed.

func (*Conn) Header

func (c *Conn) Header() (Header, error)

func (*Conn) HeaderContext

func (c *Conn) HeaderContext(ctx context.Context) (Header, error)

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) Read

func (c *Conn) Read(b []byte) (n int, err error)

func (*Conn) ReadFrom

func (c *Conn) ReadFrom(r io.Reader) (n int64, err error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) Write

func (c *Conn) Write(b []byte) (n int, err error)

func (*Conn) WriteTo

func (c *Conn) WriteTo(w io.Writer) (n int64, err error)
type Header struct {
	// Source is the ip address of the party that initiated the connection
	Source net.Addr
	// Destination is the ip address the remote party connected to; aka the address
	// the proxy was listening for connections on.
	Destination net.Addr
	// True if the proxy header was UNKNOWN (v1) or if proto was set to LOCAL (v2)
	// In which case Header.Source and Header.Destination will both be nil. TLVs still
	// maybe available if v2, and Header.Unknown will be populated if v1.
	IsLocal bool
	// The version of the proxy protocol parsed
	Version int
	// The unparsed TLVs (Type-Length-Value) that were appended to the end of
	// the v2 proto proxy header.
	RawTLVs []byte
	// Contains the complete header minus the cRLF if the proto was UNKNOWN
	Unknown []byte
}

func ReadHeader

func ReadHeader(r io.Reader) (*Header, error)

func ReadV2Header

func ReadV2Header(r io.Reader) (*Header, error)

ReadV2Header assumes the first read will contain the identifier, then reads up until the length of the header as specified by the proxy protocol header. If you are using a bufio.Reader you can peek at the first 13 bytes to ensure the header identifier exists before passing the bufio.Reader to this function.

func (*Header) ParseTLVs

func (h *Header) ParseTLVs() (map[byte][]byte, error)

ParseTLVs parses the Header.RawTLVS byte string into a TLV map.

type Listener

type Listener struct {
	net.Listener
	ReadHeaderTimeout time.Duration
	TestingSkipConnfu bool
}

func (*Listener) Accept

func (l *Listener) Accept() (net.Conn, error)

Jump to

Keyboard shortcuts

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