From 917127059a4a27da09b29fc25d367e81fd88b5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Matczuk?= Date: Tue, 17 Sep 2024 12:11:37 +0200 Subject: [PATCH] protocol: use smaller read buffer size --- protocol.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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, }