mirror of
https://github.com/WJQSERVER-STUDIO/ghproxy.git
synced 2026-02-04 00:31:10 +08:00
Merge pull request #123 from WJQSERVER-STUDIO/dev
Some checks are pending
Build / prepare (push) Waiting to run
Build / build (amd64, darwin) (push) Blocked by required conditions
Build / build (amd64, freebsd) (push) Blocked by required conditions
Build / build (amd64, linux) (push) Blocked by required conditions
Build / build (arm64, darwin) (push) Blocked by required conditions
Build / build (arm64, freebsd) (push) Blocked by required conditions
Build / build (arm64, linux) (push) Blocked by required conditions
Build / docker (push) Blocked by required conditions
Some checks are pending
Build / prepare (push) Waiting to run
Build / build (amd64, darwin) (push) Blocked by required conditions
Build / build (amd64, freebsd) (push) Blocked by required conditions
Build / build (amd64, linux) (push) Blocked by required conditions
Build / build (arm64, darwin) (push) Blocked by required conditions
Build / build (arm64, freebsd) (push) Blocked by required conditions
Build / build (arm64, linux) (push) Blocked by required conditions
Build / docker (push) Blocked by required conditions
3.5.4
This commit is contained in:
commit
96c30889f4
9 changed files with 58 additions and 18 deletions
19
CHANGELOG.md
19
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
|
3.5.3 - 2025-06-13
|
||||||
---
|
---
|
||||||
- CHANGE: 显式配置`WithStreamBody(true)`
|
- CHANGE: 显式配置`WithStreamBody(true)`
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
25w45a
|
25w46c
|
||||||
|
|
@ -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.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/) 双重许可, 您可从中选择一个使用
|
||||||
|
|
||||||
前端位于单独仓库中, 且各个主题均存在各自的许可证, 本项目许可证并不包括前端
|
前端位于单独仓库中, 且各个主题均存在各自的许可证, 本项目许可证并不包括前端
|
||||||
|
|
||||||
|
|
|
||||||
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
||||||
3.5.3
|
3.5.4
|
||||||
2
main.go
2
main.go
|
|
@ -507,7 +507,7 @@ func main() {
|
||||||
proxy.NoRouteHandler(cfg, limiter, iplimiter)(ctx, c)
|
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")
|
c.Set("matcher", "api")
|
||||||
proxy.RoutingHandler(cfg, limiter, iplimiter)(ctx, c)
|
proxy.RoutingHandler(cfg, limiter, iplimiter)(ctx, c)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -23,16 +23,17 @@ 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 {
|
||||||
resp.Body.Close()
|
err := resp.Body.Close()
|
||||||
}
|
if err != nil {
|
||||||
if req != nil {
|
logError("Failed to close response body: %v", err)
|
||||||
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(c.Request.BodyStream())
|
//rb.SetBody(bytes.NewBuffer(c.Request.Body()))
|
||||||
|
rb.SetBody(c.RequestBodyStream())
|
||||||
rb.WithContext(ctx)
|
rb.WithContext(ctx)
|
||||||
|
|
||||||
req, err = rb.Build()
|
req, err = rb.Build()
|
||||||
|
|
@ -56,6 +57,20 @@ 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
|
||||||
|
|
@ -110,8 +125,6 @@ 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
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,16 @@ 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 {
|
||||||
resp.Body.Close()
|
err = resp.Body.Close()
|
||||||
}
|
if err != nil {
|
||||||
if req != nil {
|
logError("Failed to close response body: %v", err)
|
||||||
req.Body.Close()
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -51,7 +52,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
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,10 @@ func NoRouteHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *ra
|
||||||
|
|
||||||
// 处理blob/raw路径
|
// 处理blob/raw路径
|
||||||
if matcher == "blob" {
|
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)
|
logDebug("Matched: %v", matcher)
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,13 @@ 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 = strings.Replace(rawPath, "/blob/", "/raw/", 1)
|
rawPath = rawPath[10:]
|
||||||
|
rawPath = "raw.githubusercontent.com" + rawPath
|
||||||
|
rawPath = strings.Replace(rawPath, "/blob/", "/", 1)
|
||||||
|
matcher = "raw"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 为rawpath加入https:// 头
|
// 为rawpath加入https:// 头
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue