mirror of
https://github.com/m1k1o/neko.git
synced 2025-06-01 18:33:04 +02:00
refactor authentication code.
This commit is contained in:
parent
bc961c5170
commit
c4d67d416e
3 changed files with 18 additions and 29 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue