Commit dcea33ad authored by qiuqunfeng's avatar qiuqunfeng
Browse files

Refactor WafLogController to implement a new ReverseProxy structure, enhancing...

Refactor WafLogController to implement a new ReverseProxy structure, enhancing URL path rewriting and host assignment for improved proxy request handling.
parent 54aefec2
...@@ -30,10 +30,16 @@ func (c *WafLogController) WafLogProxy(ctx *gin.Context) { ...@@ -30,10 +30,16 @@ func (c *WafLogController) WafLogProxy(ctx *gin.Context) {
} }
log.Info().Msgf("remoteUrl: %s", remoteUrl.String()) log.Info().Msgf("remoteUrl: %s", remoteUrl.String())
proxy := httputil.NewSingleHostReverseProxy(remoteUrl) // proxy := httputil.NewSingleHostReverseProxy(remoteUrl)
proxy.Rewrite = func(req *httputil.ProxyRequest) { // proxy.Rewrite = func(req *httputil.ProxyRequest) {
req.Out.URL.Path = strings.Replace(req.In.URL.Path, "/api/v2/containerSec/waf", "/api/v2/waf", 1) // req.Out.URL.Path = strings.Replace(req.In.URL.Path, "/api/v2/containerSec/waf", "/api/v2/waf", 1)
req.Out.Host = remoteUrl.Host // req.Out.Host = remoteUrl.Host
// }
proxy := &httputil.ReverseProxy{
Rewrite: func(req *httputil.ProxyRequest) {
req.Out.URL.Host = remoteUrl.Host
req.Out.URL.Path = strings.Replace(req.In.URL.Path, "/api/v2/containerSec/waf", "/api/v2/waf", 1)
},
} }
proxy.ServeHTTP(ctx.Writer, ctx.Request) proxy.ServeHTTP(ctx.Writer, ctx.Request)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment