refactor authentication code.

This commit is contained in:
Miroslav Šedivý 2021-11-17 18:00:27 +01:00
parent bc961c5170
commit c4d67d416e
3 changed files with 18 additions and 29 deletions

View file

@ -39,12 +39,12 @@ func GetIP(serverUrl string) (string, error) {
return string(bytes.TrimSpace(buf)), nil
}
func ReadUserIP(r *http.Request) string {
func GetHttpRequestIP(r *http.Request, proxy bool) string {
IPAddress := r.Header.Get("X-Real-Ip")
if IPAddress == "" {
IPAddress = r.Header.Get("X-Forwarded-For")
}
if IPAddress == "" {
if IPAddress == "" || !proxy {
IPAddress = r.RemoteAddr
}
return IPAddress