From 8ab622d149d0f79a07ec2f045221fe718ba5d78f Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sat, 14 Jun 2025 22:05:45 +0800 Subject: [PATCH 1/4] update matcher for gist usercontent --- proxy/match.go | 36 ++++++++++++++++++++++++++++-------- proxy/matcher_test.go | 6 ++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/proxy/match.go b/proxy/match.go index 896a99b..f526461 100644 --- a/proxy/match.go +++ b/proxy/match.go @@ -10,14 +10,16 @@ import ( ) var ( - githubPrefix = "https://github.com/" - rawPrefix = "https://raw.githubusercontent.com/" - gistPrefix = "https://gist.github.com/" - apiPrefix = "https://api.github.com/" - githubPrefixLen int - rawPrefixLen int - gistPrefixLen int - apiPrefixLen int + githubPrefix = "https://github.com/" + rawPrefix = "https://raw.githubusercontent.com/" + gistPrefix = "https://gist.github.com/" + gistContentPrefix = "https://gist.githubusercontent.com/" + apiPrefix = "https://api.github.com/" + githubPrefixLen int + rawPrefixLen int + gistPrefixLen int + gistContentPrefixLen int + apiPrefixLen int ) func init() { @@ -25,6 +27,7 @@ func init() { rawPrefixLen = len(rawPrefix) gistPrefixLen = len(gistPrefix) apiPrefixLen = len(apiPrefix) + gistContentPrefixLen = len(gistContentPrefix) //log.Printf("githubPrefixLen: %d, rawPrefixLen: %d, gistPrefixLen: %d, apiPrefixLen: %d", githubPrefixLen, rawPrefixLen, gistPrefixLen, apiPrefixLen) } @@ -114,6 +117,23 @@ func Matcher(rawPath string, cfg *config.Config) (string, string, string, *GHPro return user, "", "gist", nil } + // 匹配 "https://gist.githubusercontent.com/" + if strings.HasPrefix(rawPath, gistContentPrefix) { + remaining := rawPath[gistContentPrefixLen:] + i := strings.IndexByte(remaining, '/') + if i <= 0 { + // case: https://gist.githubusercontent.com/user + // 这种情况下, gist_id 缺失, 但我们仍然可以认为 user 是有效的 + if len(remaining) > 0 { + return remaining, "", "gist", nil + } + return "", "", "", NewErrorWithStatusLookup(400, "malformed gist url: missing user") + } + // case: https://gist.githubusercontent.com/user/gist_id... + user := remaining[:i] + return user, "", "gist", nil + } + // 匹配 "https://api.github.com/" if strings.HasPrefix(rawPath, apiPrefix) { if !cfg.Auth.ForceAllowApi && (cfg.Auth.Method != "header" || !cfg.Auth.Enabled) { diff --git a/proxy/matcher_test.go b/proxy/matcher_test.go index 3293817..0c35381 100644 --- a/proxy/matcher_test.go +++ b/proxy/matcher_test.go @@ -87,6 +87,12 @@ func TestMatcher_Compatibility(t *testing.T) { config: cfgWithAuth, expectedUser: "user", expectedRepo: "", expectedMatcher: "gist", }, + { + name: "Gist UserContent Path", + rawPath: "https://gist.githubusercontent.com/user/abcdef1234567890", + config: cfgWithAuth, + expectedUser: "user", expectedRepo: "", expectedMatcher: "gist", + }, { name: "API Repos Path (with Auth)", rawPath: "https://api.github.com/repos/owner/repo/pulls", From 1b06260a14f5c057ad3393aacb006a093c46a2ff Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sat, 14 Jun 2025 22:11:31 +0800 Subject: [PATCH 2/4] 25w47a --- CHANGELOG.md | 5 +++++ DEV-VERSION | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d323c99..e0064c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +25w47a - 2025-06-14 +--- +- PRE-RELEASE: 此版本是v3.5.5预发布版本,请勿在生产环境中使用; +- CHANGE: 修正新匹配器的覆盖问题, 同时增加test的覆盖 + 3.5.4 - 2025-06-14 --- - CHANGE: 移植来自于[GHProxy-Touka](https://github.com/WJQSERVER-STUDIO/ghproxy-touka)的blob处理逻辑与302处理逻辑 diff --git a/DEV-VERSION b/DEV-VERSION index 7b8b745..55564ab 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w46c \ No newline at end of file +25w47a \ No newline at end of file From e0cbfed1e7fecdd0788c44416dc220b888a1a1aa Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sat, 14 Jun 2025 22:17:13 +0800 Subject: [PATCH 3/4] 3.5.5 --- CHANGELOG.md | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0064c0..006230b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # 更新日志 +3.5.5 - 2025-06-14 +--- +- CHANGE: 修正新匹配器的覆盖问题, 同时增加test的覆盖 + 25w47a - 2025-06-14 --- - PRE-RELEASE: 此版本是v3.5.5预发布版本,请勿在生产环境中使用; diff --git a/VERSION b/VERSION index e5b8a84..1947319 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.5.4 \ No newline at end of file +3.5.5 \ No newline at end of file From 0008366e07001218519c033edd30fb4fe84d7c1e Mon Sep 17 00:00:00 2001 From: wjqserver <114663932+WJQSERVER@users.noreply.github.com> Date: Sat, 14 Jun 2025 23:06:11 +0800 Subject: [PATCH 4/4] 25w48a --- CHANGELOG.md | 5 +++++ DEV-VERSION | 2 +- proxy/chunkreq.go | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 006230b..b6bec5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +25w48a - 2025-06-14 +--- +- PRE-RELEASE: 此版本是v3.5.6预发布版本,请勿在生产环境中使用; +- CHANGE: 测试302重定向逻辑 + 3.5.5 - 2025-06-14 --- - CHANGE: 修正新匹配器的覆盖问题, 同时增加test的覆盖 diff --git a/DEV-VERSION b/DEV-VERSION index 55564ab..219b720 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w47a \ No newline at end of file +25w48a \ No newline at end of file diff --git a/proxy/chunkreq.go b/proxy/chunkreq.go index 35461c9..287da4c 100644 --- a/proxy/chunkreq.go +++ b/proxy/chunkreq.go @@ -68,6 +68,7 @@ func ChunkedProxyRequest(ctx context.Context, c *app.RequestContext, u string, c c.Request.Header.Del("Referer") logInfo("Internal Redirecting to %s", finalURL) ChunkedProxyRequest(ctx, c, finalURL, cfg, matcher) + return } }