X-Forward-For can return a list
This commit is contained in:
parent
a7023cee3a
commit
becd5526f5
1 changed files with 17 additions and 9 deletions
26
httplog.go
26
httplog.go
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
/* This default icon is empty with a long lived cache */
|
/* This default icon is empty with a long lived cache */
|
||||||
DefaultFavIcon FavIcon = defaultFavIcon{}
|
DefaultFavIcon FavIcon = defaultFavIcon{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -63,19 +63,27 @@ func LogRequest(r *http.Request, statusCode int) {
|
||||||
r.ContentLength)
|
r.ContentLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RealIP(r *http.Request) (ip string) {
|
func RealIP(r *http.Request) string {
|
||||||
ip = r.RemoteAddr
|
rip := RealIPs(r)
|
||||||
|
return rip[len(rip)]
|
||||||
|
}
|
||||||
|
|
||||||
|
func RealIPs(r *http.Request) (ips []string) {
|
||||||
|
ip := r.RemoteAddr
|
||||||
|
|
||||||
port_pos := strings.LastIndex(ip, ":")
|
port_pos := strings.LastIndex(ip, ":")
|
||||||
if port_pos != -1 {
|
if port_pos != -1 {
|
||||||
ip = ip[0:port_pos]
|
ip = ip[0:port_pos]
|
||||||
}
|
}
|
||||||
|
if ip != "" {
|
||||||
for k, v := range r.Header {
|
ips = append(ips, ip)
|
||||||
if k == "X-Forwarded-For" {
|
|
||||||
ip = strings.Join(v, " ")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ip
|
val := r.Header.Get("X-Forwarded-For")
|
||||||
|
if val != "" {
|
||||||
|
for _, ip := range strings.Split(val, ", ") {
|
||||||
|
ips = append(ips, ip)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ips
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue