util.go 275 B

1234567891011121314
  1. package httpx
  2. import "net/http"
  3. const xForwardedFor = "X-Forwarded-For"
  4. // GetRemoteAddr returns the peer address, supports X-Forward-For.
  5. func GetRemoteAddr(r *http.Request) string {
  6. v := r.Header.Get(xForwardedFor)
  7. if len(v) > 0 {
  8. return v
  9. }
  10. return r.RemoteAddr
  11. }