Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya <74469029+voronin9032@users.noreply.github.com>2024-08-11 19:26:43 +0300
committerGitHub <noreply@github.com>2024-08-11 19:26:43 +0300
commit438a9684ee04caf353020bc0d8c0cea19aa4ee5c (patch)
treed99327b9d9f9a1fde895c0bdb2592d057171d182 /sub/subController.go
parenta6000f22a214445f85aeecc1956938d196dc43a2 (diff)
Fix #2470 (The subscription service gives two ports for VLESS) (#2479)v2.3.13
* Fix #2470
Diffstat (limited to 'sub/subController.go')
-rw-r--r--sub/subController.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/sub/subController.go b/sub/subController.go
index 6212f5b2..4f23c424 100644
--- a/sub/subController.go
+++ b/sub/subController.go
@@ -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,14 @@ func (a *SUBController) subJsons(c *gin.Context) {
c.String(200, jsonSub)
}
}
+
+func getHostFromXFH(s string) (string, error) {
+ if strings.Contains(s, ":") {
+ realHost, _, err := net.SplitHostPort(s)
+ if err != nil {
+ return "", err
+ }
+ return realHost, nil
+ }
+ return s, nil
+}