CI / test (push) Successful in 2m32s
Routes Java Edition connections by the hostname in the handshake, with wildcard domains, backend failover, PROXY protocol v2, cached server-list status from health probes, hot-reloaded config, and an admin page and metrics endpoint. Includes CI, tagged releases and a container image. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
32 lines
844 B
Go
32 lines
844 B
Go
package proxy
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"net"
|
|
)
|
|
|
|
var v2sig = []byte("\r\n\r\n\x00\r\nQUIT\n")
|
|
|
|
// proxyV2Header builds a PROXY protocol v2 header carrying the client's real
|
|
// address so the backend can see it. Falls back to a LOCAL header if the
|
|
// addresses aren't TCP.
|
|
func proxyV2Header(src, dst net.Addr) []byte {
|
|
s, sok := src.(*net.TCPAddr)
|
|
d, dok := dst.(*net.TCPAddr)
|
|
h := append([]byte{}, v2sig...)
|
|
if !sok || !dok {
|
|
return append(h, 0x20, 0x00, 0, 0)
|
|
}
|
|
if s4, d4 := s.IP.To4(), d.IP.To4(); s4 != nil && d4 != nil {
|
|
h = append(h, 0x21, 0x11, 0, 12)
|
|
h = append(h, s4...)
|
|
h = append(h, d4...)
|
|
} else {
|
|
h = append(h, 0x21, 0x21, 0, 36)
|
|
h = append(h, s.IP.To16()...)
|
|
h = append(h, d.IP.To16()...)
|
|
}
|
|
h = binary.BigEndian.AppendUint16(h, uint16(s.Port))
|
|
return binary.BigEndian.AppendUint16(h, uint16(d.Port))
|
|
}
|