From da89b3f45ea75036eb0be5d7801d2e0848a07b0a Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Wed, 12 Mar 2025 23:01:52 +0800 Subject: [PATCH] 25w16d --- CHANGELOG.md | 5 +++++ DEV-VERSION | 2 +- proxy/chunkreq.go | 4 +++- proxy/gitreq.go | 31 +++++++++++++++++-------------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b743b69..58797f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +25w16d - 2025-03-12 +--- +- PRE-RELEASE: 此版本是v2.4.0的预发布版本,请勿在生产环境中使用; +- CHANGE: 使用更高性能的Buffer Pool 实现 + 25w16c --- - PRE-RELEASE: 此版本是v2.4.0的预发布版本,请勿在生产环境中使用; diff --git a/DEV-VERSION b/DEV-VERSION index 7ad1669..4c744ae 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w16c +25w16d \ No newline at end of file diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index 20a92f2..862743a 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -8,6 +8,7 @@ import ( "net/http" "strconv" + "github.com/WJQSERVER-STUDIO/go-utils/copyb" "github.com/gin-gonic/gin" ) @@ -126,7 +127,8 @@ func ChunkedProxyRequest(c *gin.Context, u string, cfg *config.Config, mode stri c.Status(resp.StatusCode) - _, err = io.CopyBuffer(c.Writer, resp.Body, nil) + //_, err = io.CopyBuffer(c.Writer, resp.Body, nil) + _, err = copyb.CopyBuffer(c.Writer, resp.Body, nil) if err != nil { logError("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err) return diff --git a/proxy/gitreq.go b/proxy/gitreq.go index d2971cf..5bf432b 100644 --- a/proxy/gitreq.go +++ b/proxy/gitreq.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" + "github.com/WJQSERVER-STUDIO/go-utils/copyb" "github.com/gin-gonic/gin" ) @@ -96,21 +97,12 @@ func GitReq(c *gin.Context, u string, cfg *config.Config, mode string, runMode s } c.Status(resp.StatusCode) - - // 使用固定32KB缓冲池 - buffer := BufferPool.Get().([]byte) - defer BufferPool.Put(buffer) - - _, err = io.CopyBuffer(c.Writer, resp.Body, buffer) - if err != nil { - logError("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err) - return - } else { - c.Writer.Flush() // 确保刷入 - } - /* - _, err = copyb.CopyBuffer(c.Writer, resp.Body, nil) + // 使用固定32KB缓冲池 + buffer := BufferPool.Get().([]byte) + defer BufferPool.Put(buffer) + + _, err = io.CopyBuffer(c.Writer, resp.Body, buffer) if err != nil { logError("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err) return @@ -118,6 +110,17 @@ func GitReq(c *gin.Context, u string, cfg *config.Config, mode string, runMode s c.Writer.Flush() // 确保刷入 } */ + + _, err = copyb.CopyBuffer(c.Writer, resp.Body, nil) + + if err != nil { + logError("%s %s %s %s %s Failed to copy response body: %v", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto, err) + return + } else { + + c.Writer.Flush() // 确保刷入 + } + } // extractParts 从给定的 URL 中提取所需的部分