modulepackage
0.0.0-20210106013422-671bd2870b3a
Repository: https://github.com/sebest/xff.git
Documentation: pkg.go.dev
# README
X-Forwarded-For middleware fo Go

Package xff
is a net/http
middleware/handler to parse Forwarded HTTP Extension in Golang.
Example usage
Install xff
:
go get github.com/sebest/xff
Edit server.go
:
package main
import (
"net/http"
"github.com/sebest/xff"
)
func main() {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello from " + r.RemoteAddr + "\n"))
})
xffmw, _ := xff.Default()
http.ListenAndServe(":8080", xffmw.Handler(handler))
}
Then run your server:
go run server.go
The server now runs on localhost:8080
:
$ curl -D - -H 'X-Forwarded-For: 42.42.42.42' http://localhost:8080/
HTTP/1.1 200 OK
Date: Fri, 20 Feb 2015 20:03:02 GMT
Content-Length: 29
Content-Type: text/plain; charset=utf-8
hello from 42.42.42.42:52661
# Packages
No description provided by the author
# Functions
Default creates a new XFF handler with default options.
GetRemoteAddr parses the given request, resolves the X-Forwarded-For header and returns the resolved remote address.
GetRemoteAddrIfAllowed parses the given request, resolves the X-Forwarded-For header and returns the resolved remote address if allowed.
IsPublicIP returns true if the given IP can be routed on the Internet.
New creates a new XFF handler with the provided options.
Parse parses the value of the X-Forwarded-For Header and returns the IP address.