This commit is contained in:
WJQSERVER 2025-01-19 20:24:32 +08:00
parent ef332a24e5
commit e0af54370e
5 changed files with 30 additions and 5 deletions

View file

@ -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 25w04b
--- ---
- PRE-RELEASE: 此版本是v2的候选版本(技术验证版),请勿在生产环境中使用; 我们可能会撤除v2更新计划(若技术验证版顺利通过, 则会发布v2正式版) - PRE-RELEASE: 此版本是v2的候选版本(技术验证版),请勿在生产环境中使用; 我们可能会撤除v2更新计划(若技术验证版顺利通过, 则会发布v2正式版)

View file

@ -1 +1 @@
25w04b 25w04c

View file

@ -1 +1 @@
1.8.2 1.8.3

View file

@ -91,11 +91,16 @@ func setupRateLimit(cfg *config.Config) {
} }
} }
func initBufferSize() {
proxy.InitChunkedBufferSize(cfg.Server.BufferSize)
}
func init() { func init() {
readFlag() readFlag()
flag.Parse() flag.Parse()
loadConfig() loadConfig()
setupLogger(cfg) setupLogger(cfg)
initBufferSize()
loadlist(cfg) loadlist(cfg)
setupRateLimit(cfg) setupRateLimit(cfg)

View file

@ -10,6 +10,16 @@ import (
"github.com/gin-gonic/gin" "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) { func ChunkedProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string, runMode string) {
method := c.Request.Method method := c.Request.Method
logInfo("%s %s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto) 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) CopyResponseHeaders(resp, c, cfg)
c.Status(resp.StatusCode) 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) 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 { func chunkedCopyResponseBody(c *gin.Context, respBody io.Reader) error {
buf := make([]byte, cfg.Server.BufferSize) buf := make([]byte, chunkedBufferSize)
for { for {
n, err := respBody.Read(buf) n, err := respBody.Read(buf)
if n > 0 { if n > 0 {