This commit is contained in:
yangduo 2024-07-22 17:12:48 +08:00
parent b5c9643f33
commit 97cd8e0bc7
2 changed files with 18 additions and 19 deletions

View File

@ -46,14 +46,13 @@ func CaCheck(c *gin.Context) {
cache = &pcache
}
info := new(RedirectInfo)
info.ori_req = c.Copy()
if !strings.HasSuffix(action, "S") {
CaForward(info)
CaForward(c, "", "")
return
}
info := new(RedirectInfo)
info.ori_req = c
info.sigtime = f5.GetApp().GetRealSeconds()
info.trace_id = fmt.Sprintf("%x%02x-%s", info.sigtime, len(*cache), accountId)
info.sig = q5.Md5Str(c.Request.URL.RawQuery + info.trace_id)
@ -133,7 +132,7 @@ func CheckRedirect() {
if req != nil {
redirectRequest.Store(account, req)
CaForward(req)
CaForward(req.ori_req, req.sig, req.trace_id)
}
if len(requests) == 0 {

View File

@ -9,22 +9,22 @@ import (
"github.com/gin-gonic/gin"
)
func CaForward(c *RedirectInfo) {
func CaForward(c *gin.Context, sig string, traceid string) {
queryParams := c.ori_req.Request.URL.Query()
queryParams := c.Request.URL.Query()
params := map[string]string{}
for k, v := range queryParams {
params[k] = v[0]
}
if c.sig != "" {
params["sig"] = c.sig
params["trace_id"] = c.trace_id
if sig != "" {
params["sig"] = sig
params["trace_id"] = traceid
}
fullrequrl := mt.Table.Config.GetById(0).GetRedirectUrl() + c.ori_req.Request.URL.Path
fullrequrl := mt.Table.Config.GetById(0).GetRedirectUrl() + c.Request.URL.Path
cb := func(rsp f5.HttpCliResponse) {
if rsp.GetErr() != nil {
c.ori_req.JSON(http.StatusOK, gin.H{
c.JSON(http.StatusOK, gin.H{
"errcode": 1004,
"errmsg": rsp.GetErr(),
})
@ -32,10 +32,10 @@ func CaForward(c *RedirectInfo) {
}
// fmt.Println("saved ori context:", c.ori_req)
c.ori_req.JSON(http.StatusOK, rsp.GetRawData())
c.JSON(http.StatusOK, rsp.GetRawData())
}
switch c.ori_req.Request.Method {
switch c.Request.Method {
case "GET":
f5.GetHttpCliMgr().SendGoStyleRequest(
fullrequrl,
@ -45,15 +45,15 @@ func CaForward(c *RedirectInfo) {
f5.GetHttpCliMgr().SendGoStylePost(
fullrequrl,
params,
c.ori_req.ContentType(),
q5.GetPostBody(c.ori_req.Request),
c.ContentType(),
q5.GetPostBody(c.Request),
cb)
}
if c.sig != "" {
account := c.ori_req.DefaultQuery("account_id", "")
if sig != "" {
account := c.DefaultQuery("account_id", "")
v, exist := redirectRequest.Load(account)
if exist && (*v).trace_id == c.trace_id {
if exist && (*v).trace_id == traceid {
redirectRequest.Delete(account)
}
}