go-zero/rest/httpx/util.go

15 lines
269 B
Go
Raw Normal View History

2020-08-12 12:25:52 +08:00
package httpx
2020-07-29 18:00:04 +08:00
import "net/http"
const xForwardFor = "X-Forward-For"
2021-02-09 13:50:21 +08:00
// GetRemoteAddr returns the peer address, supports X-Forward-For.
2020-07-29 18:00:04 +08:00
func GetRemoteAddr(r *http.Request) string {
v := r.Header.Get(xForwardFor)
if len(v) > 0 {
return v
}
return r.RemoteAddr
}