mirror of
https://github.com/mpolden/echoip.git
synced 2024-11-10 07:27:22 +01:00
Read X-Real-IP header if set
This commit is contained in:
parent
dc96c778e9
commit
f1a8819fa7
@ -26,7 +26,14 @@ func handler(w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
host, _, err := net.SplitHostPort(req.RemoteAddr)
|
||||
var host string
|
||||
var err error
|
||||
realIP := req.Header.Get("X-Real-IP")
|
||||
if realIP != "" {
|
||||
host = realIP
|
||||
} else {
|
||||
host, _, err = net.SplitHostPort(req.RemoteAddr)
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("Failed to parse remote address: %s\n", req.RemoteAddr)
|
||||
http.Error(w, "Failed to parse remote address", 500)
|
||||
|
Loading…
Reference in New Issue
Block a user