mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
Merge branch 'master' of https://github.com/gogf/gf into gvalid_Example
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
@ -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")
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user