Merge branch 'master' of https://github.com/gogf/gf into gvalid_Example

This commit is contained in:
huangqian
2021-12-06 22:20:15 +08:00
3 changed files with 9 additions and 5 deletions

View File

@ -216,7 +216,7 @@ func (r *Request) GetClientIp() string {
func (r *Request) GetRemoteIp() string {
array, _ := gregex.MatchString(`(.+):(\d+)`, r.RemoteAddr)
if len(array) > 1 {
return array[1]
return strings.Trim(array[1], "[]")
}
return r.RemoteAddr
}

View File

@ -32,10 +32,14 @@ func TestRequest_GetRemoteIp(t *testing.T) {
time.Sleep(100 * time.Millisecond)
client := g.Client()
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
clientV4 := g.Client()
clientV4.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
t.Assert(client.GetContent(ctx, "/"), "127.0.0.1")
clientV6 := g.Client()
clientV6.SetPrefix(fmt.Sprintf("http://[::1]:%d", p))
t.Assert(clientV4.GetContent(ctx, "/"), "127.0.0.1")
t.Assert(clientV6.GetContent(ctx, "/"), "::1")
})
}

View File

@ -24,7 +24,7 @@ func IsSubDomain(subDomain string, mainDomain string) bool {
// Eg:
// "s.s.goframe.org" is not sub-domain of "*.goframe.org"
// but
// "s.s.goframe.org" is not sub-domain of "goframe.org"
// "s.s.goframe.org" is sub-domain of "goframe.org"
if mainLength > 2 && subLength > mainLength {
return false
}