From 0008366e07001218519c033edd30fb4fe84d7c1e Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sat, 14 Jun 2025 23:06:11 +0800 Subject: [PATCH 1/5] 25w48a --- CHANGELOG.md | 5 +++++ DEV-VERSION | 2 +- proxy/chunkreq.go | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 006230b..b6bec5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +25w48a - 2025-06-14 +--- +- PRE-RELEASE: 此版本是v3.5.6预发布版本,请勿在生产环境中使用; +- CHANGE: 测试302重定向逻辑 + 3.5.5 - 2025-06-14 --- - CHANGE: 修正新匹配器的覆盖问题, 同时增加test的覆盖 diff --git a/DEV-VERSION b/DEV-VERSION index 55564ab..219b720 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w47a \ No newline at end of file +25w48a \ No newline at end of file diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index 35461c9..287da4c 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -68,6 +68,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c c.Request.Header.Del("Referer") logInfo("Internal Redirecting to %s", finalURL) ChunkedProxyRequest(ctx, c, finalURL, cfg, matcher) + return } } From cf5ae0d184e93b243c83a78a62a76e5125105496 Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sun, 15 Jun 2025 11:02:16 +0800 Subject: [PATCH 2/5] fix blob rewrite --- proxy/handler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy/handler.go b/proxy/handler.go index 80a5892..d5fe677 100644 --- a/proxy/handler.go +++ b/proxy/handler.go @@ -68,8 +68,8 @@ func NoRouteHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *ra // 处理blob/raw路径 if matcher == "blob" { - rawPath = rawPath[10:] - rawPath = "raw.githubusercontent.com" + rawPath + rawPath = rawPath[18:] + rawPath = "https://raw.githubusercontent.com" + rawPath rawPath = strings.Replace(rawPath, "/blob/", "/", 1) matcher = "raw" } From fd7e270db4515d22375fc609ffbf63980a11b03a Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sun, 15 Jun 2025 15:14:15 +0800 Subject: [PATCH 3/5] 25w48b --- CHANGELOG.md | 6 ++++++ DEV-VERSION | 2 +- config/config.go | 19 +++++++++++-------- config/config.toml | 1 + go.mod | 5 +---- go.sum | 4 ++-- main.go | 12 ++++++++++++ proxy/chunkreq.go | 2 ++ proxy/gitreq.go | 1 + proxy/reqheader.go | 25 +++++++++++++++++++------ 10 files changed, 56 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6bec5b..68f814f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +25w48b - 2025-06-15 +--- +- PRE-RELEASE: 此版本是v3.5.6预发布版本,请勿在生产环境中使用; +- FIX: 修正blob重写的生成问题 +- CHANGE: 验证与连接释放相关的修正 + 25w48a - 2025-06-14 --- - PRE-RELEASE: 此版本是v3.5.6预发布版本,请勿在生产环境中使用; diff --git a/DEV-VERSION b/DEV-VERSION index 219b720..52b7a35 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w48a \ No newline at end of file +25w48b \ No newline at end of file diff --git a/config/config.go b/config/config.go index 0060b63..5c5023a 100644 --- a/config/config.go +++ b/config/config.go @@ -26,6 +26,7 @@ type Config struct { host = "0.0.0.0" port = 8080 netlib = "netpoll" # "netpoll" / "std" "standard" "net/http" "net" +goPoolSize = 1024 sizeLimit = 125 # MB memLimit = 0 # MB H2C = true @@ -38,6 +39,7 @@ type ServerConfig struct { Host string `toml:"host"` NetLib string `toml:"netlib"` SenseClientDisconnection bool `toml:"senseClientDisconnection"` + GoPoolSize int `toml:"goPoolSize"` SizeLimit int `toml:"sizeLimit"` MemLimit int64 `toml:"memLimit"` H2C bool `toml:"H2C"` @@ -224,14 +226,15 @@ func FileExists(filename string) bool { func DefaultConfig() *Config { return &Config{ Server: ServerConfig{ - Port: 8080, - Host: "0.0.0.0", - NetLib: "netpoll", - SizeLimit: 125, - MemLimit: 0, - H2C: true, - Cors: "*", - Debug: false, + Port: 8080, + Host: "0.0.0.0", + NetLib: "netpoll", + GoPoolSize: 1024, + SizeLimit: 125, + MemLimit: 0, + H2C: true, + Cors: "*", + Debug: false, }, Httpc: HttpcConfig{ Mode: "auto", diff --git a/config/config.toml b/config/config.toml index 9ef2662..b60cb13 100644 --- a/config/config.toml +++ b/config/config.toml @@ -3,6 +3,7 @@ host = "0.0.0.0" port = 8080 netlib = "netpoll" # "netpoll" / "std" "standard" "net/http" "net" senseClientDisconnection = false +goPoolSize = 1024 sizeLimit = 125 # MB memLimit = 0 # MB H2C = true diff --git a/go.mod b/go.mod index ba6d974..b606255 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/BurntSushi/toml v1.5.0 github.com/WJQSERVER-STUDIO/httpc v0.7.0 github.com/WJQSERVER-STUDIO/logger v1.8.0 - github.com/cloudwego/hertz v0.10.0 + github.com/cloudwego/hertz v0.10.1-0.20250611091639-3dde619f5598 github.com/hertz-contrib/http2 v0.1.8 golang.org/x/net v0.41.0 golang.org/x/time v0.12.0 @@ -44,6 +44,3 @@ require ( ) replace github.com/nyaruka/phonenumbers => github.com/nyaruka/phonenumbers v1.6.1 // 1.6.3 has reflect leaking - -//replace github.com/WJQSERVER-STUDIO/httpc v0.5.1 => /data/github/WJQSERVER-STUDIO/httpc -//replace github.com/WJQSERVER-STUDIO/logger v1.6.0 => /data/github/WJQSERVER-STUDIO/logger diff --git a/go.sum b/go.sum index d8d7e39..730d2c6 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCy github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/gopkg v0.1.4 h1:EoQiCG4sTonTPHxOGE0VlQs+sQR+Hsi2uN0qqwu8O50= github.com/cloudwego/gopkg v0.1.4/go.mod h1:FQuXsRWRsSqJLsMVd5SYzp8/Z1y5gXKnVvRrWUOsCMI= -github.com/cloudwego/hertz v0.10.0 h1:V0vmBaLdQPlgL6w2TA6PZL1g6SGgQznFx6vqxWdCcKw= -github.com/cloudwego/hertz v0.10.0/go.mod h1:lRBohmcDkGx5TLK6QKFGdzJ6n3IXqGueHsOiXcYgXA4= +github.com/cloudwego/hertz v0.10.1-0.20250611091639-3dde619f5598 h1:8tVol3hNJS7+7f7yQIkP57tZMzUV3fOhn6pQ7t4R06k= +github.com/cloudwego/hertz v0.10.1-0.20250611091639-3dde619f5598/go.mod h1:lRBohmcDkGx5TLK6QKFGdzJ6n3IXqGueHsOiXcYgXA4= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cloudwego/netpoll v0.7.0 h1:bDrxQaNfijRI1zyGgXHQoE/nYegL0nr+ijO1Norelc4= github.com/cloudwego/netpoll v0.7.0/go.mod h1:PI+YrmyS7cIr0+SD4seJz3Eo3ckkXdu2ZVKBLhURLNU= diff --git a/main.go b/main.go index 7d6fb0e..a31f075 100644 --- a/main.go +++ b/main.go @@ -431,6 +431,7 @@ func main() { server.WithHostPorts(addr), server.WithTransport(standard.NewTransporter), server.WithStreamBody(true), + server.WithIdleTimeout(30*time.Second), ) r.AddProtocol("h2", factory.NewServerFactory()) } else { @@ -438,6 +439,7 @@ func main() { server.WithHostPorts(addr), server.WithTransport(standard.NewTransporter), server.WithStreamBody(true), + server.WithIdleTimeout(30*time.Second), ) } } else if cfg.Server.NetLib == "netpoll" || cfg.Server.NetLib == "" { @@ -447,6 +449,7 @@ func main() { server.WithHostPorts(addr), server.WithSenseClientDisconnection(cfg.Server.SenseClientDisconnection), server.WithStreamBody(true), + server.WithIdleTimeout(30*time.Second), ) r.AddProtocol("h2", factory.NewServerFactory()) } else { @@ -454,6 +457,7 @@ func main() { server.WithHostPorts(addr), server.WithSenseClientDisconnection(cfg.Server.SenseClientDisconnection), server.WithStreamBody(true), + server.WithIdleTimeout(30*time.Second), ) } } else { @@ -462,6 +466,14 @@ func main() { os.Exit(1) } + /* + if cfg.Server.GoPoolSize > 0 { + gopool.SetCap(int32(cfg.Server.GoPoolSize)) + } else { + gopool.SetCap(1024) + } + */ + r.Use(recovery.Recovery()) // Recovery中间件 r.Use(loggin.Middleware()) // log中间件 r.Use(viaHeader()) diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index 287da4c..8c977c9 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -28,6 +28,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c logError("Failed to close response body: %v", err) } } + c.Abort() }() rb := client.NewRequestBuilder(string(c.Request.Method()), u) @@ -152,6 +153,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c return } c.SetBodyStream(bodyReader, -1) + bodyReader.Close() } } diff --git a/proxy/gitreq.go b/proxy/gitreq.go index de6bff7..6d00640 100644 --- a/proxy/gitreq.go +++ b/proxy/gitreq.go @@ -144,4 +144,5 @@ func GitReq(ctx context.Context, c *app.RequestContext, u string, cfg *config.Co } c.SetBodyStream(bodyReader, -1) + bodyReader.Close() } diff --git a/proxy/reqheader.go b/proxy/reqheader.go index 8400821..ddb1fc6 100644 --- a/proxy/reqheader.go +++ b/proxy/reqheader.go @@ -49,6 +49,16 @@ var ( } ) +// copyHeader 将所有头部从 src 复制到 dst。 +// 对于多值头部,它会为每个值调用 Add,从而保留所有值。 +func copyHeader(dst, src http.Header) { + for k, vv := range src { + for _, v := range vv { + dst.Add(k, v) + } + } +} + func setRequestHeaders(c *app.RequestContext, req *http.Request, cfg *config.Config, matcher string) { if matcher == "raw" && cfg.Httpc.UseCustomRawHeaders { // 使用预定义Header @@ -56,20 +66,23 @@ func setRequestHeaders(c *app.RequestContext, req *http.Request, cfg *config.Con req.Header.Set(key, value) } } else if matcher == "clone" { + c.Request.Header.VisitAll(func(key, value []byte) { headerKey := string(key) headerValue := string(value) - if _, shouldRemove := cloneHeadersToRemove[headerKey]; !shouldRemove { - req.Header.Set(headerKey, headerValue) - } + req.Header.Set(headerKey, headerValue) }) + for key := range cloneHeadersToRemove { + req.Header.Del(key) + } } else { c.Request.Header.VisitAll(func(key, value []byte) { headerKey := string(key) headerValue := string(value) - if _, shouldRemove := reqHeadersToRemove[headerKey]; !shouldRemove { - req.Header.Set(headerKey, headerValue) - } + req.Header.Set(headerKey, headerValue) }) + for key := range cloneHeadersToRemove { + req.Header.Del(key) + } } } From 97b1f69f999e0cf6dc5b9bbae598cbf57679c102 Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sun, 15 Jun 2025 15:51:50 +0800 Subject: [PATCH 4/5] 25w48c --- CHANGELOG.md | 5 +++++ DEV-VERSION | 2 +- proxy/chunkreq.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68f814f..bb10be8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +25w48c - 2025-06-15 +--- +- PRE-RELEASE: 此版本是v3.5.6预发布版本,请勿在生产环境中使用; +- CHANGE: 加入内部301处理 + 25w48b - 2025-06-15 --- - PRE-RELEASE: 此版本是v3.5.6预发布版本,请勿在生产环境中使用; diff --git a/DEV-VERSION b/DEV-VERSION index 52b7a35..b100103 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w48b \ No newline at end of file +25w48c \ No newline at end of file diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index 8c977c9..124cfb7 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -59,7 +59,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c } // 处理302情况 - if resp.StatusCode == 302 { + if resp.StatusCode == 302 || resp.StatusCode == 301 { finalURL := resp.Header.Get("Location") if finalURL != "" { err = resp.Body.Close() From 91c3ad7fd8e9a2fcbac9ee01edc30135fed255f6 Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sun, 15 Jun 2025 16:42:42 +0800 Subject: [PATCH 5/5] 3.5.6 --- CHANGELOG.md | 5 +++++ VERSION | 2 +- proxy/reqheader.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb10be8..019844d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +3.5.6 - 2025-06-15 +--- +- FIX: 修正blob重写的生成问题 +- CHANGE: 改进302重定向逻辑 + 25w48c - 2025-06-15 --- - PRE-RELEASE: 此版本是v3.5.6预发布版本,请勿在生产环境中使用; diff --git a/VERSION b/VERSION index 1947319..01081db 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.5.5 \ No newline at end of file +3.5.6 \ No newline at end of file diff --git a/proxy/reqheader.go b/proxy/reqheader.go index ddb1fc6..8612a7e 100644 --- a/proxy/reqheader.go +++ b/proxy/reqheader.go @@ -81,7 +81,7 @@ func setRequestHeaders(c *app.RequestContext, req *http.Request, cfg *config.Con headerValue := string(value) req.Header.Set(headerKey, headerValue) }) - for key := range cloneHeadersToRemove { + for key := range reqHeadersToRemove { req.Header.Del(key) } }