Skip to content

Commit 9171270

Browse files
mmatczukpires
authored andcommitted
protocol: use smaller read buffer size
1 parent 424fc80 commit 9171270

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

protocol.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,13 @@ func (p *Listener) Addr() net.Addr {
134134
// NewConn is used to wrap a net.Conn that may be speaking
135135
// the proxy protocol into a proxyproto.Conn
136136
func NewConn(conn net.Conn, opts ...func(*Conn)) *Conn {
137+
// For v1 the header length is at most 108 bytes.
138+
// For v2 the header length is at most 52 bytes plus the length of the TLVs.
139+
// We use 256 bytes to be safe.
140+
const bufSize = 256
141+
137142
pConn := &Conn{
138-
bufReader: bufio.NewReader(conn),
143+
bufReader: bufio.NewReaderSize(conn, bufSize),
139144
conn: conn,
140145
}
141146

0 commit comments

Comments
 (0)