-
Notifications
You must be signed in to change notification settings - Fork 155
Open
Description
I was hoping to use go-httpbin today to figure out what the ip of my load balancer actually comes through as, but it was masked by the cloudflare CDN the request went through
Could you return the .RemoteAddr field somewhere in the response?
Code
Lines 44 to 66 in 00a70e7
| func getClientIP(r *http.Request) string { | |
| // Special case some hosting platforms that provide the value directly. | |
| if clientIP := r.Header.Get("Fly-Client-IP"); clientIP != "" { | |
| return clientIP | |
| } | |
| if clientIP := r.Header.Get("CF-Connecting-IP"); clientIP != "" { | |
| return clientIP | |
| } | |
| if clientIP := r.Header.Get("Fastly-Client-IP"); clientIP != "" { | |
| return clientIP | |
| } | |
| if clientIP := r.Header.Get("True-Client-IP"); clientIP != "" { | |
| return clientIP | |
| } | |
| // Try to pull a reasonable value from the X-Forwarded-For header, if | |
| // present, by taking the first entry in a comma-separated list of IPs. | |
| if forwardedFor := r.Header.Get("X-Forwarded-For"); forwardedFor != "" { | |
| return strings.TrimSpace(strings.SplitN(forwardedFor, ",", 2)[0]) | |
| } | |
| // Finally, fall back on the actual remote addr from the request. | |
| return r.RemoteAddr |