Skip to content

Commit

Permalink
get host from header in proxy call
Browse files Browse the repository at this point in the history
  • Loading branch information
alireza0 committed Nov 2, 2024
1 parent ebf45c2 commit 088eb6d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 9 additions & 2 deletions sub/subController.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sub
import (
"encoding/base64"
"net"
"strings"

"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -55,7 +56,10 @@ func (a *SUBController) initRouter(g *gin.RouterGroup) {

func (a *SUBController) subs(c *gin.Context) {
subId := c.Param("subid")
host, _, _ := net.SplitHostPort(c.Request.Host)
host := c.Request.Host
if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 {
host, _, _ = net.SplitHostPort(c.Request.Host)
}
subs, header, err := a.subService.GetSubs(subId, host)
if err != nil || len(subs) == 0 {
c.String(400, "Error!")
Expand All @@ -80,7 +84,10 @@ func (a *SUBController) subs(c *gin.Context) {

func (a *SUBController) subJsons(c *gin.Context) {
subId := c.Param("subid")
host, _, _ := net.SplitHostPort(c.Request.Host)
host := c.Request.Host
if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 {
host, _, _ = net.SplitHostPort(c.Request.Host)
}
jsonSub, header, err := a.subJsonService.GetJson(subId, host)
if err != nil || len(jsonSub) == 0 {
c.String(400, "Error!")
Expand Down
6 changes: 5 additions & 1 deletion web/controller/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func html(c *gin.Context, name string, title string, data gin.H) {
data = gin.H{}
}
data["title"] = title
data["host"], _, _ = net.SplitHostPort(c.Request.Host)
host := c.Request.Host
if colonIndex := strings.LastIndex(host, ":"); colonIndex != -1 {
host, _, _ = net.SplitHostPort(c.Request.Host)
}
data["host"] = host
data["request_uri"] = c.Request.RequestURI
data["base_path"] = c.GetString("base_path")
c.HTML(http.StatusOK, name, getContext(data))
Expand Down

0 comments on commit 088eb6d

Please sign in to comment.