diff --git a/go.mod b/go.mod index a844df8..6ba07ff 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/pires/go-proxyproto +module github.com/bollenberger/go-proxyproto go 1.24 diff --git a/protocol.go b/protocol.go index 93cf7c4..5c55bb7 100644 --- a/protocol.go +++ b/protocol.go @@ -153,8 +153,8 @@ func (p *Listener) Addr() net.Addr { 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 + // We use 65535, as it's the maximum length representable by a uint16. + const bufSize = 65535 br := bufio.NewReaderSize(conn, bufSize) pConn := &Conn{ diff --git a/v2.go b/v2.go index 74bf3f0..6e73d8b 100644 --- a/v2.go +++ b/v2.go @@ -5,6 +5,7 @@ import ( "bytes" "encoding/binary" "errors" + "fmt" "io" "net" ) @@ -98,7 +99,7 @@ func parseVersion2(reader *bufio.Reader) (header *Header, err error) { return nil, ErrCantReadLength } if !header.validateLength(length) { - return nil, ErrInvalidLength + return nil, fmt.Errorf("%w: length == %d, header.TransportProtocol == %d", ErrInvalidLength, length, header.TransportProtocol) } // Return early if the length is zero, which means that @@ -108,7 +109,7 @@ func parseVersion2(reader *bufio.Reader) (header *Header, err error) { } if _, err := reader.Peek(int(length)); err != nil { - return nil, ErrInvalidLength + return nil, fmt.Errorf("%w: %w", ErrInvalidLength, err) } // Length-limited reader for payload section