From 880d57822ef3aefe1e98ffc9ca49d77a37ded13b Mon Sep 17 00:00:00 2001 From: Pires Date: Wed, 8 Sep 2021 11:03:49 +0100 Subject: [PATCH] protocol: DEFAULT_TIMEOUT is now DefaultReadHeaderTimeout Signed-off-by: Pires --- protocol.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/protocol.go b/protocol.go index 60b83cf..bfc24e9 100644 --- a/protocol.go +++ b/protocol.go @@ -8,7 +8,11 @@ import ( "time" ) -var DEFAULT_TIMEOUT = 200 * time.Millisecond +// DefaultReadHeaderTimeout is how long header processing waits for header to +// be read from the wire, if Listener.ReaderHeaderTimeout is not set. +// It's kept as a global variable so to make it easier to find and override, +// e.g. go build -ldflags -X "github.com/pires/go-proxyproto.DefaultReadHeaderTimeout=1s" +var DefaultReadHeaderTimeout = 200 * time.Millisecond // Listener is used to wrap an underlying listener, // whose connections may be using the HAProxy Proxy Protocol. @@ -77,9 +81,9 @@ func (p *Listener) Accept() (net.Conn, error) { ValidateHeader(p.ValidateHeader), ) - // If the ReadHeaderTimeout for the listener is 0, set a default of 200ms + // If the ReadHeaderTimeout for the listener is unset, use the default timeout. if p.ReadHeaderTimeout == 0 { - p.ReadHeaderTimeout = DEFAULT_TIMEOUT + p.ReadHeaderTimeout = DefaultReadHeaderTimeout } // Set the readHeaderTimeout of the new conn to the value of the listener