Skip to content

everettcaleb/go-proxyproto

Repository files navigation

go-proxyproto

Go Report Card Go Doc Release

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.

Using this Library

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 to net.Listen)
  • ListenTLS (equivalent to tls.Listen)
  • ListenAndServeHTTP (equivalent to http.ListenAndServe)
  • ListenAndServeHTTPS (roughly equivalent to http.ListenAndServeTLS)

TODO

  • 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

About

Proxy Protocol Library with support for v1, v2, and SSL TLV extensions

Resources

License

Stars

Watchers

Forks

Packages

No packages published