20 lines
498 B
Go
20 lines
498 B
Go
|
package controller
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"slices"
|
||
|
)
|
||
|
|
||
|
// Returns the request's original IP address, resolving the `x-forwarded-for`
|
||
|
// header if the request originates from a trusted proxy.
|
||
|
func ResolveIP(r *http.Request) string {
|
||
|
trustedProxies := []string{ "10.4.20.69" }
|
||
|
if slices.Contains(trustedProxies, r.RemoteAddr) {
|
||
|
forwardedFor := r.Header.Get("x-forwarded-for")
|
||
|
if len(forwardedFor) > 0 {
|
||
|
return forwardedFor
|
||
|
}
|
||
|
}
|
||
|
return r.RemoteAddr
|
||
|
}
|