From a7be65a111bce5b7cb72a4c71eb9f6c31953a71c Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Fri, 25 Apr 2025 17:14:33 +0800 Subject: [PATCH] 25w31t-1 --- DEV-VERSION | 2 +- main.go | 4 ++++ proxy/chunkreq.go | 1 - proxy/ghcr.go | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 proxy/ghcr.go diff --git a/DEV-VERSION b/DEV-VERSION index 1fecf83..8dfa506 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w30e \ No newline at end of file +25w31t-1 \ No newline at end of file diff --git a/main.go b/main.go index 5314f31..8dce53f 100644 --- a/main.go +++ b/main.go @@ -459,6 +459,10 @@ func main() { proxy.RoutingHandler(cfg, limiter, iplimiter)(ctx, c) }) + r.Any("/v2/*filepath", func(ctx context.Context, c *app.RequestContext) { + proxy.GhcrRouting(cfg)(ctx, c) + }) + r.NoRoute(func(ctx context.Context, c *app.RequestContext) { proxy.NoRouteHandler(cfg, limiter, iplimiter)(ctx, c) }) diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index f68b07f..13be45a 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -52,7 +52,6 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c } setRequestHeaders(c, req) - //removeWSHeader(req) // 删除Conection Upgrade头, 避免与HTTP/2冲突(检查是否存在Upgrade头) AuthPassThrough(c, cfg, req) resp, err = client.Do(req) diff --git a/proxy/ghcr.go b/proxy/ghcr.go new file mode 100644 index 0000000..71d764d --- /dev/null +++ b/proxy/ghcr.go @@ -0,0 +1,14 @@ +package proxy + +import ( + "context" + "ghproxy/config" + + "github.com/cloudwego/hertz/pkg/app" +) + +func GhcrRouting(cfg *config.Config) app.HandlerFunc { + return func(ctx context.Context, c *app.RequestContext) { + ChunkedProxyRequest(ctx, c, "https://ghcr.io"+string(c.Request.RequestURI()), cfg, "ghcr") + } +}