The remote host of the client. When the 'X-Forwarded-For' header is set, then its value is used as is.
(r *http.Request)
| 70 | // The remote host of the client. When the 'X-Forwarded-For' |
| 71 | // header is set, then its value is used as is. |
| 72 | func remoteHost(r *http.Request) string { |
| 73 | ff := r.Header.Get("X-Forwarded-For") |
| 74 | if ff != "" { |
| 75 | result := make([]string, 0) |
| 76 | for s := range strings.SplitSeq(ff, ", ") { |
| 77 | addr, err := netip.ParseAddr(stripPort(s)) |
| 78 | if err != nil { |
| 79 | continue // ignore bogus entries from XFF |
| 80 | } |
| 81 | result = append(result, addr.String()) |
| 82 | } |
| 83 | return strings.Join(result, ", ") |
| 84 | } |
| 85 | return stripPort(r.RemoteAddr) |
| 86 | } |
| 87 | |
| 88 | func omitWhitespace(h string) string { |
| 89 | if h != "" { |