{"modulePath":"github.com/InkerBot/proxyprotocol","version":"v0.0.0-20230718180101-462257948fc5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package proxyprotocol\n\nPackage proxyprotocol implements version 1 and 2 of the PROXY protocol.\n\n[https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt](https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt)\n\n## Types\n\n```go\ntype Cmd byte\n```\nCmd indicates the PROXY command being used.\n\n```go\nconst (\n\t// CmdLocal indicates the connection was established on purpose by the proxy without being relayed.\n\tCmdLocal Cmd = 0x00\n\n\t// CmdProxy the connection was established on behalf of another node, and reflects the original connection endpoints.\n\tCmdProxy Cmd = 0x01\n)\n```\n\n```go\ntype Conn struct {\n\tnet.Conn\n\t// contains filtered or unexported fields\n}\n```\nConn wraps a net.Conn using the PROXY protocol to determin LocalAddr() and RemoteAddr().\n\n```go\nfunc NewConn(c net.Conn, deadline time.Time) *Conn\n```\nNewConn will wrap an existing net.Conn using \\`deadline\\` to receive the header.\n\n```go\nfunc (c *Conn) LocalAddr() net.Addr\n```\nLocalAddr returns the local network address provided by the PROXY header.\n\n```go\nfunc (c *Conn) ProxyHeader() (Header, error)\n```\nProxyHeader will return the PROXY header received on the current connection.\n\n```go\nfunc (c *Conn) Read(p []byte) (int, error)\n```\nRead reads data from the connection, after parsing the PROXY header.\n\n```go\nfunc (c *Conn) RemoteAddr() net.Addr\n```\nRemoteAddr returns the remote network address provided by the PROXY header.\n\n```go\nfunc (c *Conn) SetDeadline(t time.Time) error\n```\nSetDeadline calls SetDeadline on the underlying net.Conn.\n\n```go\nfunc (c *Conn) SetReadDeadline(t time.Time) error\n```\nSetReadDeadline calls SetReadDeadline on the underlying net.Conn.\n\n```go\ntype Header interface {\n\tVersion() int\n\tSrcAddr() net.Addr\n\tDestAddr() net.Addr\n\n\tWriteTo(io.Writer) (int64, error)\n}\n```\nHeader provides information decoded from a PROXY header.\n\n```go\nfunc Parse(r *bufio.Reader) (Header, error)\n```\nParse will parse detect and return a V1 or V2 header, otherwise InvalidHeaderErr is returned.\n\n```go\ntype HeaderV1 struct {\n\tSrcPort  int\n\tSrcIP    net.IP\n\tDestPort int\n\tDestIP   net.IP\n}\n```\nHeaderV1 contains information relayed by the PROXY protocol version 1 (human-readable) header.\n\n```go\nfunc (h HeaderV1) DestAddr() net.Addr\n```\nDestAddr returns the TCP destination address.\n\n```go\nfunc (h *HeaderV1) FromConn(c net.Conn, outgoing bool)\n```\nFromConn will populate header data from the given net.Conn.\n\nThe RemoteAddr of the Conn will be considered the Source address/port and the LocalAddr of the Conn will be considered the Destination address/port for the purposes of the PROXY header if outgoing is false, if outgoing is true, the inverse is true.\n\n```go\nfunc (h HeaderV1) SrcAddr() net.Addr\n```\nSrcAddr returns the TCP source address.\n\n```go\nfunc (HeaderV1) Version() int\n```\nVersion always returns 1.\n\n```go\nfunc (h HeaderV1) WriteTo(w io.Writer) (int64, error)\n```\nWriteTo will write the V1 header to w. The proto/fam will be set to UNKNOWN if source and dest IPs are of mismatched types, or any port is out of bounds.\n\n```go\ntype HeaderV2 struct {\n\tCommand Cmd\n\tSrc     net.Addr\n\tDest    net.Addr\n}\n```\nHeaderV2 contains information relayed by the PROXY protocol version 2 (binary) header.\n\n```go\nfunc (h HeaderV2) DestAddr() net.Addr\n```\nDestAddr returns the destination address as TCP, UDP, Unix, or nil depending on Protocol and Family.\n\n```go\nfunc (h *HeaderV2) FromConn(c net.Conn, outgoing bool)\n```\nFromConn will populate header data from the given net.Conn.\n\nThe RemoteAddr of the Conn will be considered the Source address/port and the LocalAddr of the Conn will be considered the Destination address/port for the purposes of the PROXY header if outgoing is false, if outgoing is true, the inverse is true.\n\n```go\nfunc (h HeaderV2) SrcAddr() net.Addr\n```\nSrcAddr returns the source address as TCP, UDP, Unix, or nil depending on Protocol and Family.\n\n```go\nfunc (HeaderV2) Version() int\n```\nVersion always returns 2.\n\n```go\nfunc (h HeaderV2) WriteTo(w io.Writer) (int64, error)\n```\nWriteTo will write the V2 header to w. Command must be CommandProxy to send any address data.\n\n```go\ntype InvalidHeaderErr struct {\n\tRead []byte\n\t// contains filtered or unexported fields\n}\n```\nInvalidHeaderErr contains the parsing error as well as all data read from the reader.\n\n```go\ntype Listener struct {\n\tnet.Listener\n\t// contains filtered or unexported fields\n}\n```\nListener wraps a net.Listener automatically wrapping new connections with PROXY protocol support.\n\n```go\nfunc NewListener(nl net.Listener, t time.Duration) *Listener\n```\nNewListener will wrap nl, automatically handling PROXY headers for all connections. To expect PROXY headers only from certain addresses/subnets, use SetFilter.\n\nBy default, all connections must provide a PROXY header within the specified timeout.\n\n```go\nfunc (l *Listener) Accept() (net.Conn, error)\n```\nAccept waits for and returns the next connection to the listener, wrapping it with NewConn if the RemoteAddr matches any registered rules.\n\n```go\nfunc (l *Listener) Filter() []Rule\n```\nFilter returns the current set of filter rules.\n\nFilter is safe to call from multiple goroutines while the listener is in use.\n\n```go\nfunc (l *Listener) SetDefaultTimeout(t time.Duration)\n```\nSetDefaultTimeout sets the default timeout, used when the subnet filter is nil.\n\nSetDefaultTimeout is safe to call from multiple goroutines while the listener is in use.\n\n```go\nfunc (l *Listener) SetFilter(filter []Rule)\n```\nSetFilter allows limiting PROXY header requirements to matching Subnets with an optional timeout. If filter is nil, all connections will be required to provide a PROXY header (the default).\n\nConnections not matching any rule will be returned directly without reading a PROXY header.\n\nDuplicate subnet rules will automatically be removed and the lowest non-zero timeout will be used.\n\nSetFilter is safe to call from multiple goroutines while the listener is in use.\n\n```go\ntype Rule struct {\n\t// Subnet is used to match incomming IP addresses against this rule.\n\tSubnet *net.IPNet\n\n\t// Timeout indicates the max amount of time to receive the PROXY header before\n\t// terminating the connection.\n\tTimeout time.Duration\n}\n```\nRule contains configuration for a single subnet.\n\n","path":"github.com/InkerBot/proxyprotocol","name":"proxyprotocol","synopsis":"Package proxyprotocol implements version 1 and 2 of the PROXY protocol.","isRedistributable":true}
