From c13683e98211ab9016350f51e7bf198da4ad8765 Mon Sep 17 00:00:00 2001 From: CaIon Date: Tue, 12 Aug 2025 20:42:44 +0800 Subject: [PATCH] fix(auth): refine authorization header setting for messages endpoint #1575 --- middleware/auth.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/middleware/auth.go b/middleware/auth.go index ee8d9241..5f682eb6 100644 --- a/middleware/auth.go +++ b/middleware/auth.go @@ -197,8 +197,10 @@ func TokenAuth() func(c *gin.Context) { // 或者是否 x-api-key 不为空且存在anthropic-version // 谁知道有多少不符合规范没写anthropic-version的 // 所以就这样随它去吧( - if strings.Contains(c.Request.URL.Path, "/v1/messages") || (anthropicKey != "" && c.Request.Header.Get("anthropic-version") != "") { - c.Request.Header.Set("Authorization", "Bearer "+anthropicKey) + if strings.Contains(c.Request.URL.Path, "/v1/messages") { + if anthropicKey != "" { + c.Request.Header.Set("Authorization", "Bearer "+anthropicKey) + } } // gemini api 从query中获取key if strings.HasPrefix(c.Request.URL.Path, "/v1beta/models") ||