Proxy Protocol Library with support for parsing v1, v2, and SSL TLV extensions. You can find the spec for Proxy Protocol v1 and v2 here: https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt.
There's an example in cmd/http-example showing how to create an HTTP server that consumes Proxy Protocol. Here's what the code looks like:
package main
import (
"net/http"
"github.com/everettcaleb/go-proxyproto"
)
func main() {
proxyproto.ListenAndServeHTTP(":8080", echoProxyProto())
}
func echoProxyProto() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(200)
w.Write([]byte(r.RemoteAddr + "\n\n"))
}
}
The helpers available are:
Listen
(equivalent tonet.Listen
)ListenTLS
(equivalent totls.Listen
)ListenAndServeHTTP
(equivalent tohttp.ListenAndServe
)ListenAndServeHTTPS
(roughly equivalent tohttp.ListenAndServeTLS
)
- Add tests for Conn_Read
- Add code to automatically validate CRC32C TLV if present
- Add code to allow getting connection/proxy data from http.Request (not currently possible)
- Add code for generating Proxy Protocol v1/v2 payloads so library can be used to implement a reverse proxy