From b663c22bcce9afb99a59ba2450a554846df5cf61 Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 6 Aug 2024 04:23:10 +0000 Subject: [PATCH] 1 --- http.go | 5 +---- main.go | 5 +++-- ws.go | 7 ++----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/http.go b/http.go index b8ab00a..efc883b 100644 --- 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 14e89c4..9779132 100755 --- 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 144e152..8fd93a9 100644 --- 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))) -- 2.39.2