proxyprotocol

package
v1.21.11 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteLocalHeader

func WriteLocalHeader(w io.Writer) error

WriteLocalHeader will write the ProxyProtocol Header for a local connection to the provided writer

Types

type Conn

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

Conn is used to wrap and underlying connection which is speaking the Proxy Protocol. RemoteAddr() will return the address of the client instead of the proxy address.

func NewConn

func NewConn(conn net.Conn, timeout time.Duration) *Conn

NewConn is used to wrap a net.Conn speaking the proxy protocol into a proxyprotocol.Conn

func (*Conn) Close

func (p *Conn) Close() error

Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.

func (*Conn) LocalAddr

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

LocalAddr returns the local network address.

func (*Conn) Read

func (p *Conn) Read(b []byte) (int, error)

Read reads data from the connection. It will initially read the proxy protocol header. If there is an error parsing the header, it is returned and the socket is closed.

func (*Conn) ReadFrom

func (p *Conn) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads data from a provided reader and copies it to the connection.

func (*Conn) RemoteAddr

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

RemoteAddr returns the address of the client if the proxy protocol is being used, otherwise just returns the address of the socket peer. If there is an error parsing the header, the address of the client is not returned, and the socket is closed. One implication of this is that the call could block if the client is slow. Using a Deadline is recommended if this is called before Read()

func (*Conn) SetDeadline

func (p *Conn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.

A deadline is an absolute time after which I/O operations fail instead of blocking. The deadline applies to all future and pending I/O, not just the immediately following call to Read or Write. After a deadline has been exceeded, the connection can be refreshed by setting a deadline in the future.

If the deadline is exceeded a call to Read or Write or to other I/O methods will return an error that wraps os.ErrDeadlineExceeded. This can be tested using errors.Is(err, os.ErrDeadlineExceeded). The error's Timeout method will return true, but note that there are other possible errors for which the Timeout method will return true even if the deadline has not been exceeded.

An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls.

A zero value for t means I/O operations will not time out.

func (*Conn) SetReadDeadline

func (p *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out.

func (*Conn) SetWriteDeadline

func (p *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.

func (*Conn) Write

func (p *Conn) Write(b []byte) (int, error)

Write writes data to the connection. Write can be made to time out and return an error after a fixed time limit; see SetDeadline and SetWriteDeadline.

func (*Conn) WriteTo

func (p *Conn) WriteTo(w io.Writer) (int64, error)

WriteTo reads data from the connection and writes it to the writer. It will initially read the proxy protocol header. If there is an error parsing the header, it is returned and the socket is closed.

type ErrBadAddressType

type ErrBadAddressType struct {
	Address string
}

ErrBadAddressType is an error demonstrating a bad proxy header with bad Address type

func (*ErrBadAddressType) Error

func (e *ErrBadAddressType) Error() string

type ErrBadHeader

type ErrBadHeader struct {
	Header []byte
}

ErrBadHeader is an error demonstrating a bad proxy header

func (*ErrBadHeader) Error

func (e *ErrBadHeader) Error() string

type ErrBadLocal

type ErrBadLocal struct {
	IP   string
	Port string
}

ErrBadLocal is an error demonstrating a bad proxy header with bad Local

func (*ErrBadLocal) Error

func (e *ErrBadLocal) Error() string

type ErrBadRemote

type ErrBadRemote struct {
	IP   string
	Port string
}

ErrBadRemote is an error demonstrating a bad proxy header with bad Remote

func (*ErrBadRemote) Error

func (e *ErrBadRemote) Error() string

type Listener

type Listener struct {
	Listener           net.Listener
	ProxyHeaderTimeout time.Duration
	AcceptUnknown      bool // allow PROXY UNKNOWN
}

Listener is used to wrap an underlying listener, whose connections may be using the HAProxy Proxy Protocol (version 1 or 2). If the connection is using the protocol, the RemoteAddr() will return the correct client address.

Optionally define ProxyHeaderTimeout to set a maximum time to receive the Proxy Protocol Header. Zero means no timeout.

func (*Listener) Accept

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

Accept implements the Accept method in the Listener interface it waits for the next call and returns a wrapped Conn.

func (*Listener) Addr

func (p *Listener) Addr() net.Addr

Addr returns the underlying listener's network address.

func (*Listener) Close

func (p *Listener) Close() error

Close closes the underlying listener.

Jump to

Keyboard shortcuts

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