1
0
Fork 0

Use client conn to build the proxy protocol header

Co-authored-by: Simon Delicata <simon.delicata@free.fr>
This commit is contained in:
Romain 2025-09-19 10:36:05 +02:00 committed by GitHub
parent 660acf3b42
commit 5df4c270a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 77 additions and 19 deletions

View file

@ -34,7 +34,7 @@ func (p *Proxy) ServeTCP(conn WriteCloser) {
// needed because of e.g. server.trackedConnection
defer conn.Close()
connBackend, err := p.dialBackend()
connBackend, err := p.dialBackend(conn)
if err != nil {
log.Error().Err(err).Msg("Error while dialing backend")
return
@ -62,8 +62,10 @@ func (p *Proxy) ServeTCP(conn WriteCloser) {
<-errChan
}
func (p *Proxy) dialBackend() (WriteCloser, error) {
conn, err := p.dialer.Dial("tcp", p.address)
func (p *Proxy) dialBackend(clientConn net.Conn) (WriteCloser, error) {
// The clientConn is passed to the dialer so that it can use information from it if needed,
// to build a PROXY protocol header.
conn, err := p.dialer.Dial("tcp", p.address, clientConn)
if err != nil {
return nil, err
}