]> 127.0.0.1 Git - front/.git/commitdiff
1 v0.1.20240806042523
authorqydysky <qydysky@foxmail.com>
Tue, 6 Aug 2024 04:23:10 +0000 (04:23 +0000)
committerGitHub <noreply@github.com>
Tue, 6 Aug 2024 04:23:10 +0000 (04:23 +0000)
http.go
main.go
ws.go

diff --git a/http.go b/http.go
index b8ab00a5d7258c76ae5c82a8e45b0d2f02412dab..efc883b4bc69b1a389fe739b226ef6d34e4d1670 100644 (file)
--- a/http.go
+++ b/http.go
@@ -36,10 +36,7 @@ func httpDealer(ctx context.Context, w http.ResponseWriter, r *http.Request, rou
 
                url = "http" + url
 
-               if e := dealUri(&url, chosenBack.getDealerReqUri()); e != nil {
-                       logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT)))
-                       return ErrDealReqUri
-               }
+               url = dealUri(url, chosenBack.getDealerReqUri())
 
                req, e := http.NewRequestWithContext(ctx, r.Method, url, r.Body)
                if e != nil {
diff --git a/main.go b/main.go
index 14e89c4cdf761d06866e57a3ac651f917126e4a2..977913249af3922118c6f72c609945322b80ed31 100755 (executable)
--- a/main.go
+++ b/main.go
@@ -129,11 +129,12 @@ func loadConfig(ctx context.Context, buf []byte, configF File, configS *[]Config
        return md5k, nil
 }
 
-func dealUri(s *string, app []dealer.UriDealer) (e error) {
+func dealUri(s string, app []dealer.UriDealer) (t string) {
+       t = s
        for _, v := range app {
                switch v.Action {
                case `replace`:
-                       *s = regexp.MustCompile(v.MatchExp).ReplaceAllString(*s, v.Value)
+                       t = regexp.MustCompile(v.MatchExp).ReplaceAllString(t, v.Value)
                default:
                }
        }
diff --git a/ws.go b/ws.go
index 144e152fa144a86e2471fd40edeba51b97eaf884..8fd93a9047f748a8901654fa2a32350054afcc11 100644 (file)
--- a/ws.go
+++ b/ws.go
@@ -46,6 +46,8 @@ func wsDealer(ctx context.Context, w http.ResponseWriter, r *http.Request, route
 
                url = "ws" + url
 
+               url = dealUri(url, chosenBack.getDealerReqUri())
+
                reqHeader := make(http.Header)
 
                if e := copyHeader(r.Header, reqHeader, chosenBack.getDealerReqHeader()); e != nil {
@@ -53,11 +55,6 @@ func wsDealer(ctx context.Context, w http.ResponseWriter, r *http.Request, route
                        return ErrDealReqHeader
                }
 
-               if e := dealUri(&url, chosenBack.getDealerReqUri()); e != nil {
-                       logger.Warn(`W:`, fmt.Sprintf(errFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT)))
-                       return ErrDealReqUri
-               }
-
                conn, resp, e = DialContext(ctx, url, reqHeader, chosenBack)
                if e != nil && !errors.Is(e, context.Canceled) {
                        logger.Warn(`W:`, fmt.Sprintf(errFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT)))