Skip to content

Commit

Permalink
chore: add more debug log
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed Jan 16, 2025
1 parent 5b24011 commit bd01387
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,20 @@ func doHttpProxy(brk *broker, c net.Conn) {

cookie, err := req.Cookie("rtty-http-devid")
if err != nil {
log.Debug().Msg(`not found cookie "rtty-http-devid"`)
return
}
devid := cookie.Value

dev, ok := brk.devices[devid]
if !ok {
log.Debug().Msgf(`device "%s" offline`, devid)
return
}

cookie, err = req.Cookie("rtty-http-sid")
if err != nil {
log.Debug().Msgf(`not found cookie "rtty-http-sid", devid "%s"`, devid)
return
}
sid := cookie.Value
Expand Down Expand Up @@ -176,9 +179,12 @@ func doHttpProxy(brk *broker, c net.Conn) {
}
}()
} else {
log.Debug().Msgf(`not found session "%s", devid "%s"`, sid, devid)
return
}

log.Debug().Msgf("doHttpProxy devid: %s, https: %v, destaddr: %s", devid, https, hostHeaderRewrite)

hpw := &HttpProxyWriter{destAddr, srcAddr, hostHeaderRewrite, brk, dev.(*device), https}

req.Host = hostHeaderRewrite
Expand Down Expand Up @@ -293,14 +299,18 @@ func httpProxyRedirect(br *broker, c *gin.Context) {
addr := c.Param("addr")
rawPath := c.Param("path")

log.Debug().Msgf("httpProxyRedirect devid: %s, proto: %s, addr: %s, path: %s", devid, proto, addr, rawPath)

_, _, err := httpProxyVaildAddr(addr)
if err != nil {
log.Debug().Msgf("invalid addr: %s", addr)
c.Status(http.StatusBadRequest)
return
}

path, err := url.Parse(rawPath)
if err != nil {
log.Debug().Msgf("invalid path: %s", rawPath)
c.Status(http.StatusBadRequest)
return
}
Expand Down Expand Up @@ -360,6 +370,8 @@ func httpProxyRedirect(br *broker, c *gin.Context) {

domain := cfg.HttpProxyRedirDomain

log.Debug().Msgf("set cookie domain: %s", domain)

c.SetCookie("rtty-http-sid", sid, 0, "", domain, false, true)
c.SetCookie("rtty-http-devid", devid, 0, "", domain, false, true)
c.SetCookie("rtty-http-proto", proto, 0, "", domain, false, true)
Expand Down

0 comments on commit bd01387

Please sign in to comment.