Merge pull request #178 from CarlJi/20210322

fix: only replace IP when the ClientIP belongs to IPV4 model
This commit is contained in:
qiniu-bot 2021-03-23 16:09:13 +08:00 committed by GitHub
commit 6e0de18292
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,7 +136,9 @@ func (s *server) registerService(c *gin.Context) {
} }
realIP := c.ClientIP() realIP := c.ClientIP()
if host != realIP { // only for IPV4
// refer: https://github.com/qiniu/goc/issues/177
if net.ParseIP(realIP).To4() != nil && host != realIP {
log.Printf("the registered host %s of service %s is different with the real one %s, here we choose the real one", service.Name, host, realIP) log.Printf("the registered host %s of service %s is different with the real one %s, here we choose the real one", service.Name, host, realIP)
service.Address = fmt.Sprintf("http://%s:%s", realIP, port) service.Address = fmt.Sprintf("http://%s:%s", realIP, port)
} }