From 2579b3c0ba41840c52e4254e35ed248dd5a9e18d Mon Sep 17 00:00:00 2001 From: CaIon Date: Fri, 15 Aug 2025 16:08:55 +0800 Subject: [PATCH] refactor: move anthropicKey retrieval to improve authorization handling --- middleware/auth.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/middleware/auth.go b/middleware/auth.go index 5f682eb6..25caf50d 100644 --- a/middleware/auth.go +++ b/middleware/auth.go @@ -192,12 +192,9 @@ func TokenAuth() func(c *gin.Context) { } c.Request.Header.Set("Authorization", "Bearer "+key) } - anthropicKey := c.Request.Header.Get("x-api-key") // 检查path包含/v1/messages - // 或者是否 x-api-key 不为空且存在anthropic-version - // 谁知道有多少不符合规范没写anthropic-version的 - // 所以就这样随它去吧( if strings.Contains(c.Request.URL.Path, "/v1/messages") { + anthropicKey := c.Request.Header.Get("x-api-key") if anthropicKey != "" { c.Request.Header.Set("Authorization", "Bearer "+anthropicKey) }