From 732d6495ea5bee91293a3c2bd90f7895e6df418c Mon Sep 17 00:00:00 2001 From: shaw Date: Sat, 25 Apr 2026 08:58:57 +0800 Subject: [PATCH] chore(gateway): fix lint issues from cc-mimicry-parity merge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - staticcheck QF1001: apply De Morgan's law to the OAuth-mimic header passthrough guard (`!(a && b)` → `a != ... || !b`). - unused: drop `isClaudeCodeRequest`, which became dead after PR #1914 switched both `/v1/messages` and `/count_tokens` paths to unconditional `account.IsOAuth()` mimicry. The lowercase helper `isClaudeCodeClient` is kept (still referenced by `TestIsClaudeCodeClient`). --- backend/internal/service/gateway_service.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/backend/internal/service/gateway_service.go b/backend/internal/service/gateway_service.go index d9fa81ea..1713e561 100644 --- a/backend/internal/service/gateway_service.go +++ b/backend/internal/service/gateway_service.go @@ -3718,16 +3718,6 @@ func isClaudeCodeClient(userAgent string, metadataUserID string) bool { return claudeCliUserAgentRe.MatchString(userAgent) } -func isClaudeCodeRequest(ctx context.Context, c *gin.Context, parsed *ParsedRequest) bool { - if IsClaudeCodeClient(ctx) { - return true - } - if parsed == nil || c == nil { - return false - } - return isClaudeCodeClient(c.GetHeader("User-Agent"), parsed.MetadataUserID) -} - // normalizeSystemParam 将 json.RawMessage 类型的 system 参数转为标准 Go 类型(string / []any / nil), // 避免 type switch 中 json.RawMessage(底层 []byte)无法匹配 case string / case []any / case nil 的问题。 // 这是 Go 的 typed nil 陷阱:(json.RawMessage, nil) ≠ (nil, nil)。 @@ -5774,7 +5764,7 @@ func (s *GatewayService) buildUpstreamRequest(ctx context.Context, c *gin.Contex // Parrot 的 build_upstream_headers 只发 9 个精确 header,不透传任何客户端 header。 // 透传客户端 header 会引入不一致的 x-stainless-* / anthropic-beta / user-agent / // x-claude-code-session-id 等值,和我们注入的伪装 header 冲突,被 Anthropic 判 third-party。 - if !(tokenType == "oauth" && mimicClaudeCode) { + if tokenType != "oauth" || !mimicClaudeCode { for key, values := range clientHeaders { lowerKey := strings.ToLower(key) if allowedHeaders[lowerKey] {