This commit is contained in:
wjqserver 2025-06-14 07:16:43 +08:00
parent bd8412f157
commit 41395b1d72
5 changed files with 29 additions and 12 deletions

View file

@ -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

View file

@ -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)

View file

@ -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:// 头