export httpx.GetRemoteAddr

This commit is contained in:
kevin
2020-08-12 12:25:52 +08:00
parent b541403ce2
commit 80d55dbc02
6 changed files with 11 additions and 10 deletions

14
rest/httpx/util.go Normal file
View File

@@ -0,0 +1,14 @@
package httpx
import "net/http"
const xForwardFor = "X-Forward-For"
// Returns the peer address, supports X-Forward-For
func GetRemoteAddr(r *http.Request) string {
v := r.Header.Get(xForwardFor)
if len(v) > 0 {
return v
}
return r.RemoteAddr
}