Compare commits

..

No commits in common. "96c30889f480bb9eba50d87f1735794cbf6eccb0" and "bf75e62eb2f04edc532012f0c664a734423d3ffe" have entirely different histories.

9 changed files with 18 additions and 58 deletions

View file

@ -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 3.5.3 - 2025-06-13
--- ---
- CHANGE: 显式配置`WithStreamBody(true)` - CHANGE: 显式配置`WithStreamBody(true)`

View file

@ -1 +1 @@
25w46c 25w45a

View file

@ -109,7 +109,7 @@ wget -O install-dev.sh https://raw.githubusercontent.com/WJQSERVER-STUDIO/ghprox
## LICENSE ## 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/) 双重许可, 您可从中选择一个使用
前端位于单独仓库中, 且各个主题均存在各自的许可证, 本项目许可证并不包括前端 前端位于单独仓库中, 且各个主题均存在各自的许可证, 本项目许可证并不包括前端

View file

@ -1 +1 @@
3.5.4 3.5.3

View file

@ -507,7 +507,7 @@ func main() {
proxy.NoRouteHandler(cfg, limiter, iplimiter)(ctx, c) 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") c.Set("matcher", "api")
proxy.RoutingHandler(cfg, limiter, iplimiter)(ctx, c) proxy.RoutingHandler(cfg, limiter, iplimiter)(ctx, c)
}) })

View file

@ -23,17 +23,16 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
go func() { go func() {
<-ctx.Done() <-ctx.Done()
if resp != nil && resp.Body != nil { if resp != nil && resp.Body != nil {
err := resp.Body.Close() resp.Body.Close()
if err != nil {
logError("Failed to close response body: %v", err)
} }
if req != nil {
req.Body.Close()
} }
}() }()
rb := client.NewRequestBuilder(string(c.Request.Method()), u) rb := client.NewRequestBuilder(string(c.Request.Method()), u)
rb.NoDefaultHeaders() rb.NoDefaultHeaders()
//rb.SetBody(bytes.NewBuffer(c.Request.Body())) rb.SetBody(c.Request.BodyStream())
rb.SetBody(c.RequestBodyStream())
rb.WithContext(ctx) rb.WithContext(ctx)
req, err = rb.Build() req, err = rb.Build()
@ -57,20 +56,6 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
return 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 ( var (
bodySize int bodySize int
contentLength string 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) bodyReader = limitreader.NewRateLimitedReader(bodyReader, bandwidthLimit, int(bandwidthBurst), ctx)
} }
defer bodyReader.Close()
if MatcherShell(u) && matchString(matcher) && cfg.Shell.Editor { if MatcherShell(u) && matchString(matcher) && cfg.Shell.Editor {
// 判断body是不是gzip // 判断body是不是gzip
var compress string var compress string

View file

@ -17,16 +17,15 @@ func GitReq(ctx context.Context, c *app.RequestContext, u string, cfg *config.Co
var ( var (
req *http.Request req *http.Request
resp *http.Response resp *http.Response
err error
) )
go func() { go func() {
<-ctx.Done() <-ctx.Done()
if resp != nil && resp.Body != nil { if resp != nil && resp.Body != nil {
err = resp.Body.Close() resp.Body.Close()
if err != nil {
logError("Failed to close response body: %v", err)
} }
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.SetBody(reqBodyReader)
rb.WithContext(ctx) rb.WithContext(ctx)
req, err = rb.Build() req, err := rb.Build()
if err != nil { if err != nil {
HandleError(c, fmt.Sprintf("Failed to create request: %v", err)) HandleError(c, fmt.Sprintf("Failed to create request: %v", err))
return return

View file

@ -68,10 +68,7 @@ func NoRouteHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *ra
// 处理blob/raw路径 // 处理blob/raw路径
if matcher == "blob" { if matcher == "blob" {
rawPath = rawPath[10:] rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1)
rawPath = "raw.githubusercontent.com" + rawPath
rawPath = strings.Replace(rawPath, "/blob/", "/", 1)
matcher = "raw"
} }
logDebug("Matched: %v", matcher) logDebug("Matched: %v", matcher)

View file

@ -48,13 +48,9 @@ func RoutingHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *ra
return return
} }
// 处理blob/raw路径
// 处理blob/raw路径 // 处理blob/raw路径
if matcher == "blob" { if matcher == "blob" {
rawPath = rawPath[10:] rawPath = strings.Replace(rawPath, "/blob/", "/raw/", 1)
rawPath = "raw.githubusercontent.com" + rawPath
rawPath = strings.Replace(rawPath, "/blob/", "/", 1)
matcher = "raw"
} }
// 为rawpath加入https:// 头 // 为rawpath加入https:// 头