This commit is contained in:
John Guo
2021-12-07 19:09:09 +08:00
4 changed files with 10 additions and 6 deletions

View File

@ -64,7 +64,7 @@ The `Web` component performance of `GoFrame`, please refer to third-party projec
- [ZTE](https://www.zte.com.cn/china/)
- [Ant Financial Services](https://www.antfin.com/)
- [VIVO](https://www.vivo.com/)
- [MedLinker](https://www.vivo.com/)
- [MedLinker](https://www.medlinker.com/)
- [KuCoin](https://www.kucoin.io/)
- [LeYouJia](https://www.leyoujia.com/)
- [IGG](https://igg.com)

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
}