From 547a3a1d02ca4d42a5d772d5718571f5a4e0b0f8 Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 18 Mar 2025 05:55:21 +0000 Subject: [PATCH] 1 --- config.go | 47 +++++++++++++++++++++-------------------------- http.go | 30 +++++++++++++++--------------- local.go | 10 +++++----- ws.go | 22 +++++++++++----------- 4 files changed, 52 insertions(+), 57 deletions(-) diff --git a/config.go b/config.go index 231949c..7f8ada6 100755 --- a/config.go +++ b/config.go @@ -14,6 +14,7 @@ import ( "strconv" "strings" "sync" + "sync/atomic" "time" "github.com/dustin/go-humanize" @@ -45,6 +46,8 @@ type Config struct { routeP pweb.WebPath routeMap sync.Map `json:"-"` Routes []Route `json:"routes"` + + reqId atomic.Int64 `json:"-"` } func (t *Config) Run(ctx context.Context, logger Logger) { @@ -135,39 +138,41 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) { logger.Info(`I:`, fmt.Sprintf("%v > %v", t.Addr, k)) t.routeMap.Store(k, route) - var logFormat = "%v %v%v %v %v" + var logFormat = "%d %v %v%v %v %v" for _, routePath := range route.Path { t.routeP.Store(routePath, func(w http.ResponseWriter, r *http.Request) { + reqId := t.reqId.Add(1) + if len(r.RequestURI) > 8000 { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrUriTooLong)) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrUriTooLong)) w.Header().Add(header+"Error", ErrUriTooLong.Error()) w.WriteHeader(http.StatusBadRequest) return } if ok, e := route.Filiter.ReqUri.Match(r); e != nil { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", e)) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "Err", e)) } else if !ok { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrPatherCheckFail)) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrPatherCheckFail)) w.Header().Add(header+"Error", ErrPatherCheckFail.Error()) w.WriteHeader(http.StatusForbidden) return } if ok, e := route.Filiter.ReqHeader.Match(r.Header); e != nil { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", e)) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "Err", e)) } else if !ok { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrHeaderCheckFail)) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrHeaderCheckFail)) w.Header().Add(header+"Error", ErrHeaderCheckFail.Error()) w.WriteHeader(http.StatusForbidden) return } if ok, e := route.Filiter.ReqBody.Match(r); e != nil { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", e)) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "Err", e)) } else if !ok { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrBodyCheckFail)) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrBodyCheckFail)) w.Header().Add(header+"Error", ErrBodyCheckFail.Error()) w.WriteHeader(http.StatusForbidden) return @@ -190,7 +195,7 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) { } if e, ok := filiter(backP.(*Back)); e != nil { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", e)) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "Err", e)) } else if ok { for i := uint(0); i < backP.(*Back).Weight; i++ { backIs = append(backIs, backP.(*Back)) @@ -211,7 +216,7 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) { } if len(backIs) == 0 { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrNoRoute)) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrNoRoute)) w.Header().Add(header+"Error", ErrNoRoute.Error()) w.WriteHeader(http.StatusNotFound) return @@ -220,7 +225,7 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) { var e error = ErrAllBacksFail type reqDealer interface { - Deal(ctx context.Context, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error + Deal(ctx context.Context, reqId int64, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error } // repack @@ -239,18 +244,8 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) { reqBufUsed = true n, _ := r.Body.Read(reqBuf) reqBuf = reqBuf[:n] - // if n, _ := r.Body.Read(reqBuf); n == cap(reqBuf) { - // logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", ErrReqReBodyOverflow)) - // w.Header().Add(header+"Error", ErrReqReBodyOverflow.Error()) - // w.WriteHeader(http.StatusServiceUnavailable) - // return - // } - // logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", ErrReqReBodyFail)) - // w.Header().Add(header+"Error", ErrReqReBodyFail.Error()) - // w.WriteHeader(http.StatusServiceUnavailable) - // return } else { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", ErrReqReBodyOverflow)) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "Err", ErrReqReBodyOverflow)) } } } @@ -270,11 +265,11 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) { } if !strings.Contains(backP.To, "://") { - e = component2.Get[reqDealer]("local").Deal(r.Context(), w, r, routePath, backP, logger, t.BlocksI) + e = component2.Get[reqDealer]("local").Deal(r.Context(), reqId, w, r, routePath, backP, logger, t.BlocksI) } else if strings.ToLower((r.Header.Get("Upgrade"))) == "websocket" { - e = component2.Get[reqDealer]("ws").Deal(r.Context(), w, r, routePath, backP, logger, t.BlocksI) + e = component2.Get[reqDealer]("ws").Deal(r.Context(), reqId, w, r, routePath, backP, logger, t.BlocksI) } else { - e = component2.Get[reqDealer]("http").Deal(r.Context(), w, r, routePath, backP, logger, t.BlocksI) + e = component2.Get[reqDealer]("http").Deal(r.Context(), reqId, w, r, routePath, backP, logger, t.BlocksI) } if e == nil { @@ -286,7 +281,7 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) { // some err can't retry break } - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, route.config.Addr, routePath, "Err", ErrReqRetry)) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "Err", ErrReqRetry)) } if e != nil { diff --git a/http.go b/http.go index 8927edb..6db6dd0 100644 --- a/http.go +++ b/http.go @@ -18,7 +18,7 @@ import ( func init() { type I interface { - Deal(ctx context.Context, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error + Deal(ctx context.Context, reqId int64, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error } if e := component2.Register[I]("http", httpDealer{}); e != nil { panic(e) @@ -27,11 +27,11 @@ func init() { type httpDealer struct{} -func (httpDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error { +func (httpDealer) Deal(ctx context.Context, reqId int64, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error { var ( opT = time.Now() resp *http.Response - logFormat = "%v %v%v > %v http %v %v %v" + logFormat = "%v %v %v%v > %v http %v %v %v" ) url := chosenBack.To @@ -45,7 +45,7 @@ func (httpDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Reque req, e := http.NewRequestWithContext(ctx, r.Method, url, r.Body) if e != nil { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", e, time.Since(opT))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", e, time.Since(opT))) chosenBack.Disable() return MarkRetry(ErrReqCreFail) } @@ -53,7 +53,7 @@ func (httpDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Reque // if e := copyHeader(r.Header, req.Header, chosenBack.getDealerReqHeader()) // ; e != nil { - // logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT))) + // logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT))) // return ErrDealReqHeader // } @@ -79,10 +79,10 @@ func (httpDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Reque return } } else { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", ErrCerVerify, time.Since(opT))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", ErrCerVerify, time.Since(opT))) } } else if err != ErrEmptyVerifyPeerCerByte { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", err, time.Since(opT))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", err, time.Since(opT))) } client := http.Client{ @@ -94,13 +94,13 @@ func (httpDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Reque resp, e = client.Do(req) if e != nil && !errors.Is(e, ErrRedirect) && !errors.Is(e, context.Canceled) { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", e, time.Since(opT))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", e, time.Since(opT))) chosenBack.Disable() return MarkRetry(ErrResFail) } if chosenBack.getErrToSec() != 0 && time.Since(opT).Seconds() > chosenBack.getErrToSec() { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", ErrResTO, time.Since(opT))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", ErrResTO, time.Since(opT))) chosenBack.Disable() } @@ -109,14 +109,14 @@ func (httpDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Reque } if ok, e := chosenBack.getFiliterResHeader().Match(resp.Header); e != nil { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", e, time.Since(opT))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", e, time.Since(opT))) } else if !ok { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", ErrHeaderCheckFail, time.Since(opT))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", ErrHeaderCheckFail, time.Since(opT))) w.Header().Add(header+"Error", ErrHeaderCheckFail.Error()) return MarkRetry(ErrHeaderCheckFail) } - logger.Debug(`T:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, r.Method, r.RequestURI, time.Since(opT))) + logger.Debug(`T:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, r.Method, r.RequestURI, time.Since(opT))) if chosenBack.route.RollRule != `` { chosenBack.be(opT) @@ -141,7 +141,7 @@ func (httpDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Reque // if e := copyHeader(resp.Header, w.Header(), chosenBack.getDealerResHeader()) // ; e != nil { - // logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT))) + // logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT))) // return ErrDealResHeader // } @@ -153,13 +153,13 @@ func (httpDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Reque defer resp.Body.Close() if tmpbuf, put, e := blocksi.Get(); e != nil { - logger.Error(`E:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT))) + logger.Error(`E:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT))) chosenBack.Disable() return ErrCopy } else { defer put() if _, e = io.CopyBuffer(w, resp.Body, tmpbuf); e != nil { - logger.Error(`E:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT))) + logger.Error(`E:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT))) if !errors.Is(e, context.Canceled) { chosenBack.Disable() } diff --git a/local.go b/local.go index e94f4e0..1f1cbc9 100644 --- a/local.go +++ b/local.go @@ -16,7 +16,7 @@ import ( func init() { type I interface { - Deal(ctx context.Context, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error + Deal(ctx context.Context, reqId int64, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error } if e := component2.Register[I]("local", localDealer{}); e != nil { panic(e) @@ -25,7 +25,7 @@ func init() { type localDealer struct{} -func (localDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error { +func (localDealer) Deal(ctx context.Context, reqId int64, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error { var ( opT = time.Now() logFormat = "%v %v%v > %v local %v %v %v" @@ -34,7 +34,7 @@ func (localDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Requ path := chosenBack.To if chosenBack.PathAdd() { if s, e := url.PathUnescape(r.URL.Path); e != nil { - logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", e, time.Since(opT))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "Err", e, time.Since(opT))) return ErrDealReqUri } else { path += s @@ -48,11 +48,11 @@ func (localDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Requ // if e := copyHeader(http.Header{}, w.Header(), chosenBack.getDealerResHeader()) // ; e != nil { - // logger.Warn(`W:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT))) + // logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, "BLOCK", e, time.Since(opT))) // return ErrDealResHeader // } - logger.Debug(`T:`, fmt.Sprintf(logFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, r.Method, r.RequestURI, time.Since(opT))) + logger.Debug(`T:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, r.Method, r.RequestURI, time.Since(opT))) http.ServeFile(w, r.WithContext(ctx), path) return nil diff --git a/ws.go b/ws.go index 903925b..8324ba9 100644 --- a/ws.go +++ b/ws.go @@ -27,7 +27,7 @@ import ( func init() { type I interface { - Deal(ctx context.Context, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error + Deal(ctx context.Context, reqId int64, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error } if e := component2.Register[I]("ws", wsDealer{}); e != nil { panic(e) @@ -36,12 +36,12 @@ func init() { type wsDealer struct{} -func (wsDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error { +func (wsDealer) Deal(ctx context.Context, reqId int64, w http.ResponseWriter, r *http.Request, routePath string, chosenBack *Back, logger Logger, blocksi pslice.BlocksI[byte]) error { var ( opT = time.Now() resp *http.Response conn net.Conn - errFormat = "%v %v > %v > %v ws %v %v" + logFormat = "%v %v > %v > %v ws %v %v" ) // for i := 0; i < len(backs) && (resp == nil || conn == nil); i++ { @@ -64,20 +64,20 @@ func (wsDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Request // if e := copyHeader(r.Header, reqHeader, chosenBack.getDealerReqHeader()) // ; e != nil { - // logger.Warn(`W:`, fmt.Sprintf(errFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT))) + // logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT))) // return ErrDealReqHeader // } var e error 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))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT))) chosenBack.Disable() return MarkRetry(ErrResFail) } if chosenBack.getErrToSec() != 0 && time.Since(opT).Seconds() > chosenBack.getErrToSec() { - logger.Warn(`W:`, fmt.Sprintf(errFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, ErrResTO, time.Since(opT))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, ErrResTO, time.Since(opT))) chosenBack.Disable() } // } @@ -91,9 +91,9 @@ func (wsDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Request } if ok, e := chosenBack.getFiliterResHeader().Match(resp.Header); e != nil { - logger.Warn(`W:`, fmt.Sprintf(errFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT))) } else if !ok { - logger.Warn(`W:`, fmt.Sprintf(errFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, ErrHeaderCheckFail, time.Since(opT))) + logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, ErrHeaderCheckFail, time.Since(opT))) w.Header().Add(header+"Error", ErrHeaderCheckFail.Error()) return MarkRetry(ErrHeaderCheckFail) } @@ -126,7 +126,7 @@ func (wsDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Request // if e := copyHeader(resp.Header, resHeader, chosenBack.getDealerResHeader()) // ; e != nil { - // logger.Warn(`W:`, fmt.Sprintf(errFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT))) + // logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT))) // return ErrDealResHeader // } @@ -141,7 +141,7 @@ func (wsDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Request if !errors.Is(e, context.Canceled) { chosenBack.Disable() } - logger.Error(`E:`, fmt.Sprintf(errFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT))) + logger.Error(`E:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT))) return ErrCopy } case e := <-copyWsMsg(conn, req, blocksi): @@ -149,7 +149,7 @@ func (wsDealer) Deal(ctx context.Context, w http.ResponseWriter, r *http.Request if !errors.Is(e, context.Canceled) { chosenBack.Disable() } - logger.Error(`E:`, fmt.Sprintf(errFormat, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT))) + logger.Error(`E:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, chosenBack.route.config.Addr, routePath, chosenBack.Name, e, time.Since(opT))) return ErrCopy } case <-ctx.Done(): -- 2.39.2