use strings.Split instead of strings.IndexByte

This commit is contained in:
thinkerou 2018-06-22 21:16:01 +08:00
parent caf3e350a5
commit 15ee05bcc2

10
context.go Executable file → Normal file
View File

@ -539,14 +539,10 @@ func (c *Context) ShouldBindBodyWith(
func (c *Context) ClientIP() string { func (c *Context) ClientIP() string {
if c.engine.ForwardedByClientIP { if c.engine.ForwardedByClientIP {
clientIP := c.requestHeader("X-Forwarded-For") clientIP := c.requestHeader("X-Forwarded-For")
if index := strings.IndexByte(clientIP, ','); index >= 0 { clientIP = strings.TrimSpace(strings.Split(clientIP, ",")[0])
clientIP = clientIP[0:index] if clientIP == "" {
clientIP = strings.TrimSpace(c.requestHeader("X-Real-Ip"))
} }
clientIP = strings.TrimSpace(clientIP)
if clientIP != "" {
return clientIP
}
clientIP = strings.TrimSpace(c.requestHeader("X-Real-Ip"))
if clientIP != "" { if clientIP != "" {
return clientIP return clientIP
} }