Documentation ¶
Index ¶
- func WriteLocalHeader(w io.Writer) error
- type Conn
- func (p *Conn) Close() error
- func (p *Conn) LocalAddr() net.Addr
- func (p *Conn) Read(b []byte) (int, error)
- func (p *Conn) ReadFrom(r io.Reader) (int64, error)
- func (p *Conn) RemoteAddr() net.Addr
- func (p *Conn) SetDeadline(t time.Time) error
- func (p *Conn) SetReadDeadline(t time.Time) error
- func (p *Conn) SetWriteDeadline(t time.Time) error
- func (p *Conn) Write(b []byte) (int, error)
- func (p *Conn) WriteTo(w io.Writer) (int64, error)
- type ErrBadAddressType
- type ErrBadHeader
- type ErrBadLocal
- type ErrBadRemote
- type Listener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteLocalHeader ¶
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 ¶
NewConn is used to wrap a net.Conn speaking the proxy protocol into a proxyprotocol.Conn
func (*Conn) Close ¶
Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.
func (*Conn) Read ¶
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) RemoteAddr ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
ErrBadLocal is an error demonstrating a bad proxy header with bad Local
func (*ErrBadLocal) Error ¶
func (e *ErrBadLocal) Error() string
type ErrBadRemote ¶
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 ¶
Accept implements the Accept method in the Listener interface it waits for the next call and returns a wrapped Conn.