mirror of https://github.com/gin-gonic/gin.git
rename validateHeader to getIPFromHeader
This commit is contained in:
parent
caf2802593
commit
ebbd99aefd
14
context.go
14
context.go
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue