mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 13:22:09 +08:00
refactor: rename method to reflect use-case
This commit is contained in:
parent
a889c58de7
commit
fc3aee84b5
@ -796,7 +796,7 @@ func (c *Context) ClientIP() string {
|
|||||||
|
|
||||||
if trusted && c.engine.ForwardedByClientIP && c.engine.RemoteIPHeaders != nil {
|
if trusted && c.engine.ForwardedByClientIP && c.engine.RemoteIPHeaders != nil {
|
||||||
for _, headerName := range c.engine.RemoteIPHeaders {
|
for _, headerName := range c.engine.RemoteIPHeaders {
|
||||||
ip, valid := c.engine.validateHeader(c.requestHeader(headerName))
|
ip, valid := c.engine.getTrustedClientIP(c.requestHeader(headerName))
|
||||||
if valid {
|
if valid {
|
||||||
return ip
|
return ip
|
||||||
}
|
}
|
||||||
|
4
gin.go
4
gin.go
@ -454,8 +454,8 @@ func (engine *Engine) isTrustedProxy(ip net.IP) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateHeader will parse X-Forwarded-For header and return the trusted client IP address
|
// getTrustedClientIP will parse X-Forwarded-For header and return the trusted client IP address
|
||||||
func (engine *Engine) validateHeader(header string) (clientIP string, valid bool) {
|
func (engine *Engine) getTrustedClientIP(header string) (clientIP string, valid bool) {
|
||||||
if header == "" {
|
if header == "" {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user