From 4f449762143b6cfe7360f906a5a916b09d97c712 Mon Sep 17 00:00:00 2001 From: huangzhenpc Date: Wed, 27 Aug 2025 10:06:02 +0800 Subject: [PATCH] fix: Remove compression headers to prevent JSON parsing errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed 'invalid character '\x1f' looking for beginning of value' error caused by gzip compression in setupKillcodeHeaders function: - Removed 'Accept-Encoding: br, gzip, deflate' header that caused upstream to return compressed responses - Removed browser-specific 'sec-fetch-mode: cors' header - This prevents new-api from trying to parse compressed JSON as raw text 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- relay/channel/claude/adaptor.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/relay/channel/claude/adaptor.go b/relay/channel/claude/adaptor.go index 8031d94f..06942912 100644 --- a/relay/channel/claude/adaptor.go +++ b/relay/channel/claude/adaptor.go @@ -120,7 +120,8 @@ func setupKillcodeHeaders(c *gin.Context, req *http.Header) { req.Set("User-Agent", "B2/JS 0.51.0") req.Set("Connection", "keep-alive") req.Set("Accept", "application/json") - req.Set("Accept-Encoding", "br, gzip, deflate") + // 移除压缩请求头,避免 gzip 解析问题 + // req.Set("Accept-Encoding", "br, gzip, deflate") req.Set("Content-Type", "application/json") // Stainless SDK 特有头部 @@ -144,9 +145,9 @@ func setupKillcodeHeaders(c *gin.Context, req *http.Header) { req.Set("anthropic-beta", anthropicBeta) } - // 其他辅助头部 + // 其他辅助头部 (移除可能导致问题的头部) req.Set("accept-language", "*") - req.Set("sec-fetch-mode", "cors") + // req.Set("sec-fetch-mode", "cors") // 移除浏览器特有头部 } func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.GeneralOpenAIRequest) (any, error) {