88 "net/http"
99 "net/http/httputil"
1010 "net/url"
11+ "regexp"
12+ "strings"
1113 "sync"
1214 "time"
1315
@@ -22,14 +24,15 @@ type bufferPool struct {
2224func (bp * bufferPool ) Get () []byte {
2325 if bp .pool .New == nil {
2426 bp .pool .New = func () interface {} {
25- return make ([]byte , 32 * 1024 ) // 32KB buffer
27+ buf := make ([]byte , 32 * 1024 ) // 32KB buffer
28+ return & buf
2629 }
2730 }
28- return bp .pool .Get ().([]byte )
31+ return * ( bp .pool .Get ().(* []byte ) )
2932}
3033
3134func (bp * bufferPool ) Put (b []byte ) {
32- bp .pool .Put (b )
35+ bp .pool .Put (& b )
3336}
3437
3538func NewHandler (ctx context.Context , class service.Class , enableFakeKline bool , alwaysShowForwards bool ) func (w http.ResponseWriter , r * http.Request ) {
@@ -62,7 +65,7 @@ func (s *Handler) Router(w http.ResponseWriter, r *http.Request) {
6265 statusTracker .RecordRequest ()
6366 switch r .URL .Path {
6467 case "/status" :
65- s .status (w , r )
68+ s .status (w )
6669
6770 case "/restart" :
6871 s .restart (w , r )
@@ -105,11 +108,6 @@ func getProxyHTTPClient() *http.Client {
105108 MaxConnsPerHost : 50 ,
106109 }
107110
108- if transport == nil {
109- log .Errorf ("Failed to create HTTP transport, using default" )
110- transport = http .DefaultTransport .(* http.Transport ).Clone ()
111- }
112-
113111 proxyHTTPClient = & http.Client {
114112 Transport : transport ,
115113 Timeout : 60 * time .Second , // Longer timeout for proxy requests
@@ -377,7 +375,7 @@ func (t *banCheckTransport) RoundTrip(req *http.Request) (*http.Response, error)
377375 return resp , err
378376}
379377
380- func (s * Handler ) status (w http.ResponseWriter , r * http. Request ) {
378+ func (s * Handler ) status (w http.ResponseWriter ) {
381379 // Check if context is still valid
382380 select {
383381 case <- s .ctx .Done ():
@@ -470,17 +468,29 @@ var (
470468 logSuppressCache = make (map [string ]time.Time )
471469 logSuppressCacheLock sync.Mutex
472470 logSuppressDuration = 2 * time .Minute // Change as needed
471+
472+ normalizeNumberRegexp = regexp .MustCompile (`\b\d+(?:\.\d+)?\b` )
473+ normalizeQuotedRegexp = regexp .MustCompile (`"[^"]*"` )
474+ normalizeTimeRegexp = regexp .MustCompile (`\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?` )
473475)
474476
477+ func normalizeLogMsg (msg string ) string {
478+ msg = normalizeQuotedRegexp .ReplaceAllString (msg , "\" ?\" " )
479+ msg = normalizeTimeRegexp .ReplaceAllString (msg , "?" )
480+ msg = normalizeNumberRegexp .ReplaceAllString (msg , "?" )
481+ return strings .TrimSpace (msg )
482+ }
483+
475484// logOncePerDuration logs a message only if it hasn't been logged in the last logSuppressDuration.
476485func logOncePerDuration (level , msg string ) {
486+ key := normalizeLogMsg (msg )
477487 logSuppressCacheLock .Lock ()
478488 defer logSuppressCacheLock .Unlock ()
479- last , found := logSuppressCache [msg ]
489+ last , found := logSuppressCache [key ]
480490 if found && time .Since (last ) < logSuppressDuration {
481491 return
482492 }
483- logSuppressCache [msg ] = time .Now ()
493+ logSuppressCache [key ] = time .Now ()
484494 switch level {
485495 case "warn" :
486496 log .Warn (msg )
0 commit comments