rename validateHeader to getIPFromHeader

This commit is contained in:
daheige 2021-07-14 22:51:25 +08:00
parent caf2802593
commit ebbd99aefd
1 changed files with 11 additions and 3 deletions

View File

@ -760,7 +760,7 @@ func (c *Context) ClientIP() string {
if trusted && c.engine.ForwardedByClientIP && c.engine.RemoteIPHeaders != nil {
for _, headerName := range c.engine.RemoteIPHeaders {
ip, valid := validateHeader(c.requestHeader(headerName))
ip, valid := getIPFromHeader(c.requestHeader(headerName))
if valid {
return ip
}
@ -794,10 +794,17 @@ func (c *Context) RemoteIP() (net.IP, bool) {
return remoteIP, false
}
func validateHeader(header string) (clientIP string, valid bool) {
// getIPFromHeader return clientIP,valid when validate ip address
func getIPFromHeader(header string) (string, bool) {
if header == "" {
return "", false
}
var (
clientIP string
valid bool
)
items := strings.Split(header, ",")
for i, ipStr := range items {
ipStr = strings.TrimSpace(ipStr)
@ -814,7 +821,8 @@ func validateHeader(header string) (clientIP string, valid bool) {
valid = true
}
}
return
return clientIP, valid
}
// ContentType returns the Content-Type header of the request.