|
@@ -3,6 +3,7 @@ package sub
|
|
import (
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/base64"
|
|
"net"
|
|
"net"
|
|
|
|
+ "strings"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
)
|
|
@@ -54,7 +55,10 @@ 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")
|
|
- host := c.GetHeader("X-Forwarded-Host")
|
|
|
|
|
|
+ var host string
|
|
|
|
+ if h, err := getHostFromXFH(c.GetHeader("X-Forwarded-Host")); err == nil {
|
|
|
|
+ host = h
|
|
|
|
+ }
|
|
if host == "" {
|
|
if host == "" {
|
|
host = c.GetHeader("X-Real-IP")
|
|
host = c.GetHeader("X-Real-IP")
|
|
}
|
|
}
|
|
@@ -89,7 +93,10 @@ 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")
|
|
- host := c.GetHeader("X-Forwarded-Host")
|
|
|
|
|
|
+ var host string
|
|
|
|
+ if h, err := getHostFromXFH(c.GetHeader("X-Forwarded-Host")); err == nil {
|
|
|
|
+ host = h
|
|
|
|
+ }
|
|
if host == "" {
|
|
if host == "" {
|
|
host = c.GetHeader("X-Real-IP")
|
|
host = c.GetHeader("X-Real-IP")
|
|
}
|
|
}
|
|
@@ -113,3 +120,14 @@ func (a *SUBController) subJsons(c *gin.Context) {
|
|
c.String(200, jsonSub)
|
|
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
|
|
|
|
+}
|