From e0af54370e6a646f61b59fe5a107a711ba227d50 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Sun, 19 Jan 2025 20:24:32 +0800 Subject: [PATCH] 25w04c --- CHANGELOG.md | 10 ++++++++++ DEV-VERSION | 2 +- VERSION | 2 +- main.go | 5 +++++ proxy/chunkreq.go | 16 +++++++++++++--- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5cba82..1b6a1d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # 更新日志 +25w04c +--- +- PRE-RELEASE: 此版本是v2的候选版本,请勿在生产环境中使用; +- CHANGE: 大幅优化`proxy`核心模块, 使用Chuncked Buffer传输数据, 减少内存占用 + +v1.8.3 +--- +- RELEASE: v1.8.3, 此版本作为v1.8.2的依赖更新版本(在v2发布前, v1仍会进行漏洞修复) +- CHANGE: 更新Go版本至`1.23.5`以解决CVE漏洞 + 25w04b --- - PRE-RELEASE: 此版本是v2的候选版本(技术验证版),请勿在生产环境中使用; 我们可能会撤除v2更新计划(若技术验证版顺利通过, 则会发布v2正式版) diff --git a/DEV-VERSION b/DEV-VERSION index 6a63a51..bd1becd 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w04b \ No newline at end of file +25w04c \ No newline at end of file diff --git a/VERSION b/VERSION index 0bfbd57..fe4e75f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.8.2 \ No newline at end of file +1.8.3 \ No newline at end of file diff --git a/main.go b/main.go index cf6c057..43b7e9c 100644 --- a/main.go +++ b/main.go @@ -91,11 +91,16 @@ func setupRateLimit(cfg *config.Config) { } } +func initBufferSize() { + proxy.InitChunkedBufferSize(cfg.Server.BufferSize) +} + func init() { readFlag() flag.Parse() loadConfig() setupLogger(cfg) + initBufferSize() loadlist(cfg) setupRateLimit(cfg) diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index 7555b00..b79a788 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -10,6 +10,16 @@ import ( "github.com/gin-gonic/gin" ) +var chunkedBufferSize int + +func InitChunkedBufferSize(cfgBufferSize int) { + if cfgBufferSize == 0 { + chunkedBufferSize = 4096 // 默认缓冲区大小 + } else { + chunkedBufferSize = cfgBufferSize + } +} + func ChunkedProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string, runMode string) { method := c.Request.Method logInfo("%s %s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto) @@ -72,14 +82,14 @@ func ChunkedProxyRequest(c *gin.Context, u string, cfg *config.Config, mode stri CopyResponseHeaders(resp, c, cfg) c.Status(resp.StatusCode) - if err := chunkedCopyResponseBody(c, cfg, resp.Body); err != nil { + if err := chunkedCopyResponseBody(c, resp.Body); err != nil { logError("%s %s %s %s %s 响应复制错误: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err) } } // 复制响应体 -func chunkedCopyResponseBody(c *gin.Context, cfg *config.Config, respBody io.Reader) error { - buf := make([]byte, cfg.Server.BufferSize) +func chunkedCopyResponseBody(c *gin.Context, respBody io.Reader) error { + buf := make([]byte, chunkedBufferSize) for { n, err := respBody.Read(buf) if n > 0 {