diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c4cabe..d323c99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # 更新日志 +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 ebe0357..7b8b745 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w45a \ No newline at end of file +25w46c \ No newline at end of file diff --git a/README.md b/README.md index c388d19..3f4123d 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.0](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.1](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 678fd88..e5b8a84 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.5.3 \ No newline at end of file +3.5.4 \ No newline at end of file diff --git a/main.go b/main.go index afc923a..7d6fb0e 100644 --- a/main.go +++ b/main.go @@ -507,7 +507,7 @@ func main() { proxy.NoRouteHandler(cfg, limiter, iplimiter)(ctx, c) }) - r.GET("/api.github.com/repos/:user/:repo/*filepath", func(ctx context.Context, c *app.RequestContext) { + r.Any("/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 6e4c8f4..35461c9 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -23,16 +23,17 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c go func() { <-ctx.Done() if resp != nil && resp.Body != nil { - resp.Body.Close() - } - if req != nil { - req.Body.Close() + err := resp.Body.Close() + if err != nil { + logError("Failed to close response body: %v", err) + } } }() rb := client.NewRequestBuilder(string(c.Request.Method()), u) rb.NoDefaultHeaders() - rb.SetBody(c.Request.BodyStream()) + //rb.SetBody(bytes.NewBuffer(c.Request.Body())) + rb.SetBody(c.RequestBodyStream()) rb.WithContext(ctx) req, err = rb.Build() @@ -56,6 +57,20 @@ 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 @@ -110,8 +125,6 @@ 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 5667d21..de6bff7 100644 --- a/proxy/gitreq.go +++ b/proxy/gitreq.go @@ -17,15 +17,16 @@ 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 { - resp.Body.Close() - } - if req != nil { - req.Body.Close() + err = resp.Body.Close() + if err != nil { + logError("Failed to close response body: %v", err) + } } }() @@ -51,7 +52,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 bdd7ecb..80a5892 100644 --- a/proxy/handler.go +++ b/proxy/handler.go @@ -68,7 +68,10 @@ func NoRouteHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *ra // 处理blob/raw路径 if matcher == "blob" { - rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1) + rawPath = rawPath[10:] + rawPath = "raw.githubusercontent.com" + rawPath + rawPath = strings.Replace(rawPath, "/blob/", "/", 1) + matcher = "raw" } logDebug("Matched: %v", matcher) diff --git a/proxy/routing.go b/proxy/routing.go index a3135ec..9d68ca7 100644 --- a/proxy/routing.go +++ b/proxy/routing.go @@ -48,9 +48,13 @@ func RoutingHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *ra return } + // 处理blob/raw路径 // 处理blob/raw路径 if matcher == "blob" { - rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1) + rawPath = rawPath[10:] + rawPath = "raw.githubusercontent.com" + rawPath + rawPath = strings.Replace(rawPath, "/blob/", "/", 1) + matcher = "raw" } // 为rawpath加入https:// 头