diff --git a/protocol.go b/protocol.go index 1cdf10f..7bbb8e5 100644 --- a/protocol.go +++ b/protocol.go @@ -134,8 +134,13 @@ func (p *Listener) Addr() net.Addr { // NewConn is used to wrap a net.Conn that may be speaking // the proxy protocol into a proxyproto.Conn func NewConn(conn net.Conn, opts ...func(*Conn)) *Conn { + // For v1 the header length is at most 108 bytes. + // For v2 the header length is at most 52 bytes plus the length of the TLVs. + // We use 256 bytes to be safe. + const bufSize = 256 + pConn := &Conn{ - bufReader: bufio.NewReader(conn), + bufReader: bufio.NewReaderSize(conn, bufSize), conn: conn, }