This commit is contained in:
wjqserver 2025-06-14 06:47:47 +08:00
parent a5bf7686bd
commit d2a0177015
6 changed files with 32 additions and 14 deletions

View file

@ -1,5 +1,15 @@
# 更新日志
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)`

View file

@ -1 +1 @@
25w45a
25w46a

View file

@ -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/) 双重许可, 您可从中选择一个使用
前端位于单独仓库中, 且各个主题均存在各自的许可证, 本项目许可证并不包括前端

View file

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

View file

@ -1,6 +1,7 @@
package proxy
import (
"bytes"
"context"
"fmt"
"ghproxy/config"
@ -23,16 +24,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()
@ -110,7 +112,12 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c
bodyReader = limitreader.NewRateLimitedReader(bodyReader, bandwidthLimit, int(bandwidthBurst), ctx)
}
defer bodyReader.Close()
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

View file

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