diff --git a/CHANGELOG.md b/CHANGELOG.md index 74eeb11..5c34c60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +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预发布版本,请勿在生产环境中使用; diff --git a/DEV-VERSION b/DEV-VERSION index 99cdc41..7b8b745 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w46b \ No newline at end of file +25w46c \ No newline at end of file diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index 5fa4728..35461c9 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -57,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 @@ -111,15 +125,6 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c bodyReader = limitreader.NewRateLimitedReader(bodyReader, bandwidthLimit, int(bandwidthBurst), ctx) } - /* - defer func() { - err := bodyReader.Close() - if err != nil { - logError("Failed to close response body: %v", err) - } - }() - */ - if MatcherShell(u) && matchString(matcher) && cfg.Shell.Editor { // 判断body是不是gzip var compress string 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:// 头