mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-09-11 04:36:20 +00:00
Update subController.go
This commit is contained in:
parent
bb70e61fcd
commit
e4b9114463
1 changed files with 8 additions and 11 deletions
|
@ -56,7 +56,7 @@ func (a *SUBController) initRouter(g *gin.RouterGroup) {
|
||||||
func (a *SUBController) subs(c *gin.Context) {
|
func (a *SUBController) subs(c *gin.Context) {
|
||||||
subId := c.Param("subid")
|
subId := c.Param("subid")
|
||||||
var host string
|
var host string
|
||||||
if h, err := getHostFromXFH(c.GetHeader("X-Forwarded-Host")); err != nil {
|
if h, err := getHostFromXFH(c.GetHeader("X-Forwarded-Host")); err == nil {
|
||||||
host = h
|
host = h
|
||||||
}
|
}
|
||||||
if host == "" {
|
if host == "" {
|
||||||
|
@ -94,7 +94,7 @@ func (a *SUBController) subs(c *gin.Context) {
|
||||||
func (a *SUBController) subJsons(c *gin.Context) {
|
func (a *SUBController) subJsons(c *gin.Context) {
|
||||||
subId := c.Param("subid")
|
subId := c.Param("subid")
|
||||||
var host string
|
var host string
|
||||||
if h, err := getHostFromXFH(c.GetHeader("X-Forwarded-Host")); err != nil {
|
if h, err := getHostFromXFH(c.GetHeader("X-Forwarded-Host")); err == nil {
|
||||||
host = h
|
host = h
|
||||||
}
|
}
|
||||||
if host == "" {
|
if host == "" {
|
||||||
|
@ -121,16 +121,13 @@ func (a *SUBController) subJsons(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHostFromXFH(s string) (host string, err error) {
|
func getHostFromXFH(s string) (string, error) {
|
||||||
// X-Forwarded-Host can actually be a host:port pair, so we need to
|
if strings.Contains(s, ":") {
|
||||||
// split it
|
realHost, _, err := net.SplitHostPort(s)
|
||||||
if strings.Contains(host, ":") {
|
if err != nil {
|
||||||
if realHost, _, err := net.SplitHostPort(host); err == nil {
|
|
||||||
return realHost, nil
|
|
||||||
} else {
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
} else {
|
return realHost, nil
|
||||||
|
}
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue