util.go 254 B

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