From 4aadee7ca036ecf692209e1cc969f292c8aaf83d Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Tue, 9 Sep 2025 22:30:07 +0200 Subject: [PATCH] fix ipv6 hostname #789 --- api/apiService.go | 3 +-- api/utils.go | 5 ++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/apiService.go b/api/apiService.go index 887d301..b5fe977 100644 --- a/api/apiService.go +++ b/api/apiService.go @@ -7,7 +7,6 @@ import ( "s-ui/service" "s-ui/util" "strconv" - "strings" "time" "github.com/gin-gonic/gin" @@ -86,7 +85,7 @@ func (a *ApiService) getData(c *gin.Context) (interface{}, error) { if err != nil { return "", err } - subURI, err := a.SettingService.GetFinalSubURI(strings.Split(c.Request.Host, ":")[0]) + subURI, err := a.SettingService.GetFinalSubURI(getHostname(c)) if err != nil { return "", err } diff --git a/api/utils.go b/api/utils.go index e26230e..5257759 100644 --- a/api/utils.go +++ b/api/utils.go @@ -29,8 +29,11 @@ func getRemoteIp(c *gin.Context) string { func getHostname(c *gin.Context) string { host := c.Request.Host - if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 { + if strings.Contains(host, ":") { host, _, _ = net.SplitHostPort(c.Request.Host) + if strings.Contains(host, ":") { + host = "[" + host + "]" + } } return host }