diff --git a/CHANGELOG.md b/CHANGELOG.md index d323c99..7c4cabe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,24 +1,5 @@ # 更新日志 -3.5.4 - 2025-06-14 ---- -- CHANGE: 移植来自于[GHProxy-Touka](https://github.com/WJQSERVER-STUDIO/ghproxy-touka)的blob处理逻辑与302处理逻辑 - -25w46c - 2025-06-14 ---- -- PRE-RELEASE: 此版本是v3.5.4预发布版本,请勿在生产环境中使用; -- CHANGE: 移植来自于[GHProxy-Touka](https://github.com/WJQSERVER-STUDIO/ghproxy-touka)的blob处理逻辑与302处理逻辑 - -25w46b - 2025-06-14 ---- -- PRE-RELEASE: 此版本是v3.5.4预发布版本,请勿在生产环境中使用; -- CHANGE: 修改关闭行为以测试问题 - -25w46a - 2025-06-14 ---- -- PRE-RELEASE: 此版本是v3.5.4预发布版本,请勿在生产环境中使用; -- CHANGE: 修改payload行为以测试问题 - 3.5.3 - 2025-06-13 --- - CHANGE: 显式配置`WithStreamBody(true)` diff --git a/DEV-VERSION b/DEV-VERSION index 7b8b745..ebe0357 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w46c \ No newline at end of file +25w45a \ No newline at end of file diff --git a/README.md b/README.md index 3f4123d..c388d19 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ wget -O install-dev.sh https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghprox ## LICENSE -v3.5.2开始, 本项目使用 [WJQserver Studio License 2.1](https://wjqserver-studio.github.io/LICENSE/LICENSE.html) 和 [Mozilla Public License Version 2.0](https://mozilla.org/MPL/2.0/) 双重许可, 您可从中选择一个使用 +v3.5.2开始, 本项目使用 [WJQserver Studio License 2.0](https://wjqserver-studio.github.io/LICENSE/LICENSE.html) 和 [Mozilla Public License Version 2.0](https://mozilla.org/MPL/2.0/) 双重许可, 您可从中选择一个使用 前端位于单独仓库中, 且各个主题均存在各自的许可证, 本项目许可证并不包括前端 diff --git a/VERSION b/VERSION index e5b8a84..678fd88 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.5.4 \ No newline at end of file +3.5.3 \ No newline at end of file diff --git a/main.go b/main.go index 7d6fb0e..afc923a 100644 --- a/main.go +++ b/main.go @@ -507,7 +507,7 @@ func main() { proxy.NoRouteHandler(cfg, limiter, iplimiter)(ctx, c) }) - r.Any("/api.github.com/repos/:user/:repo/*filepath", func(ctx context.Context, c *app.RequestContext) { + r.GET("/api.github.com/repos/:user/:repo/*filepath", func(ctx context.Context, c *app.RequestContext) { c.Set("matcher", "api") proxy.RoutingHandler(cfg, limiter, iplimiter)(ctx, c) }) diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index 35461c9..6e4c8f4 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -23,17 +23,16 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c go func() { <-ctx.Done() if resp != nil && resp.Body != nil { - err := resp.Body.Close() - if err != nil { - logError("Failed to close response body: %v", err) - } + resp.Body.Close() + } + if req != nil { + req.Body.Close() } }() rb := client.NewRequestBuilder(string(c.Request.Method()), u) rb.NoDefaultHeaders() - //rb.SetBody(bytes.NewBuffer(c.Request.Body())) - rb.SetBody(c.RequestBodyStream()) + rb.SetBody(c.Request.BodyStream()) rb.WithContext(ctx) req, err = rb.Build() @@ -57,20 +56,6 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c return } - // 处理302情况 - if resp.StatusCode == 302 { - finalURL := resp.Header.Get("Location") - if finalURL != "" { - err = resp.Body.Close() - if err != nil { - logError("Failed to close response body: %v", err) - } - c.Request.Header.Del("Referer") - logInfo("Internal Redirecting to %s", finalURL) - ChunkedProxyRequest(ctx, c, finalURL, cfg, matcher) - } - } - var ( bodySize int contentLength string @@ -125,6 +110,8 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c bodyReader = limitreader.NewRateLimitedReader(bodyReader, bandwidthLimit, int(bandwidthBurst), ctx) } + defer bodyReader.Close() + if MatcherShell(u) && matchString(matcher) && cfg.Shell.Editor { // 判断body是不是gzip var compress string diff --git a/proxy/gitreq.go b/proxy/gitreq.go index de6bff7..5667d21 100644 --- a/proxy/gitreq.go +++ b/proxy/gitreq.go @@ -17,16 +17,15 @@ func GitReq(ctx context.Context, c *app.RequestContext, u string, cfg *config.Co var ( req *http.Request resp *http.Response - err error ) go func() { <-ctx.Done() if resp != nil && resp.Body != nil { - err = resp.Body.Close() - if err != nil { - logError("Failed to close response body: %v", err) - } + resp.Body.Close() + } + if req != nil { + req.Body.Close() } }() @@ -52,7 +51,7 @@ func GitReq(ctx context.Context, c *app.RequestContext, u string, cfg *config.Co rb.SetBody(reqBodyReader) rb.WithContext(ctx) - req, err = rb.Build() + req, err := rb.Build() if err != nil { HandleError(c, fmt.Sprintf("Failed to create request: %v", err)) return diff --git a/proxy/handler.go b/proxy/handler.go index 80a5892..bdd7ecb 100644 --- a/proxy/handler.go +++ b/proxy/handler.go @@ -68,10 +68,7 @@ func NoRouteHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *ra // 处理blob/raw路径 if matcher == "blob" { - rawPath = rawPath[10:] - rawPath = "raw.githubusercontent.com" + rawPath - rawPath = strings.Replace(rawPath, "/blob/", "/", 1) - matcher = "raw" + rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1) } logDebug("Matched: %v", matcher) diff --git a/proxy/routing.go b/proxy/routing.go index 9d68ca7..a3135ec 100644 --- a/proxy/routing.go +++ b/proxy/routing.go @@ -48,13 +48,9 @@ func RoutingHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *ra return } - // 处理blob/raw路径 // 处理blob/raw路径 if matcher == "blob" { - rawPath = rawPath[10:] - rawPath = "raw.githubusercontent.com" + rawPath - rawPath = strings.Replace(rawPath, "/blob/", "/", 1) - matcher = "raw" + rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1) } // 为rawpath加入https:// 头