mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-09-11 12:46:19 +00:00
Fix #2470
This commit is contained in:
parent
a6000f22a2
commit
bb70e61fcd
1 changed files with 23 additions and 2 deletions
|
@ -3,6 +3,7 @@ package sub
|
|||
import (
|
||||
"encoding/base64"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
@ -54,7 +55,10 @@ func (a *SUBController) initRouter(g *gin.RouterGroup) {
|
|||
|
||||
func (a *SUBController) subs(c *gin.Context) {
|
||||
subId := c.Param("subid")
|
||||
host := c.GetHeader("X-Forwarded-Host")
|
||||
var host string
|
||||
if h, err := getHostFromXFH(c.GetHeader("X-Forwarded-Host")); err != nil {
|
||||
host = h
|
||||
}
|
||||
if host == "" {
|
||||
host = c.GetHeader("X-Real-IP")
|
||||
}
|
||||
|
@ -89,7 +93,10 @@ func (a *SUBController) subs(c *gin.Context) {
|
|||
|
||||
func (a *SUBController) subJsons(c *gin.Context) {
|
||||
subId := c.Param("subid")
|
||||
host := c.GetHeader("X-Forwarded-Host")
|
||||
var host string
|
||||
if h, err := getHostFromXFH(c.GetHeader("X-Forwarded-Host")); err != nil {
|
||||
host = h
|
||||
}
|
||||
if host == "" {
|
||||
host = c.GetHeader("X-Real-IP")
|
||||
}
|
||||
|
@ -113,3 +120,17 @@ func (a *SUBController) subJsons(c *gin.Context) {
|
|||
c.String(200, jsonSub)
|
||||
}
|
||||
}
|
||||
|
||||
func getHostFromXFH(s string) (host string, err error) {
|
||||
// X-Forwarded-Host can actually be a host:port pair, so we need to
|
||||
// split it
|
||||
if strings.Contains(host, ":") {
|
||||
if realHost, _, err := net.SplitHostPort(host); err == nil {
|
||||
return realHost, nil
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
return s, nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue