From 70217d531a807acdc6e66579fd9650418c36a874 Mon Sep 17 00:00:00 2001 From: qydysky Date: Tue, 18 Mar 2025 07:13:51 +0000 Subject: [PATCH] 1 --- README.md | 1 + config.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3893154..c950ced 100755 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ config: - *addr*: string 监听端口 例:`0.0.0.0:8081` - *matchRule*: string 匹配规则,默认`prefix`。 `prefix`:当未匹配到时,返回最近的/匹配, `all`:当未匹配到时,返回404 +- reqIdLoop: int 请求id环大小,用于日志识别请求,默认`1000` - *copyBlocks*: int 转发的块数量,默认`1000` - *retryBlocks*: {} 重试, 当停用时,分配仅进行一次。当所有块都在使用中时,跳过。当请求没有`Content-Length`时,跳过。 - *size*: string 重试的块大小,默认`1M` diff --git a/config.go b/config.go index 7f8ada6..80bdf83 100755 --- a/config.go +++ b/config.go @@ -47,7 +47,8 @@ type Config struct { routeMap sync.Map `json:"-"` Routes []Route `json:"routes"` - reqId atomic.Int64 `json:"-"` + ReqIdLoop int `json:"reqIdLoop"` + reqId atomic.Int64 `json:"-"` } func (t *Config) Run(ctx context.Context, logger Logger) { @@ -70,6 +71,9 @@ func (t *Config) Run(ctx context.Context, logger Logger) { } } } + if t.ReqIdLoop == 0 { + t.ReqIdLoop = 1000 + } if t.BlocksI == nil { if t.CopyBlocks == 0 { t.CopyBlocks = 1000 @@ -142,7 +146,11 @@ func (t *Config) SwapSign(ctx context.Context, logger Logger) { for _, routePath := range route.Path { t.routeP.Store(routePath, func(w http.ResponseWriter, r *http.Request) { + reqId := t.reqId.Add(1) + if reqId >= int64(t.ReqIdLoop) { + t.reqId.Store(0) + } if len(r.RequestURI) > 8000 { logger.Warn(`W:`, fmt.Sprintf(logFormat, reqId, r.RemoteAddr, route.config.Addr, routePath, "BLOCK", ErrUriTooLong)) -- 2.39.2