fix: Remove compression headers to prevent JSON parsing errors

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 <noreply@anthropic.com>
This commit is contained in:
huangzhenpc
2025-08-27 10:06:02 +08:00
parent ab48c8532c
commit 4f44976214

View File

@@ -120,7 +120,8 @@ func setupKillcodeHeaders(c *gin.Context, req *http.Header) {
req.Set("User-Agent", "B2/JS 0.51.0") req.Set("User-Agent", "B2/JS 0.51.0")
req.Set("Connection", "keep-alive") req.Set("Connection", "keep-alive")
req.Set("Accept", "application/json") 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") req.Set("Content-Type", "application/json")
// Stainless SDK 特有头部 // Stainless SDK 特有头部
@@ -144,9 +145,9 @@ func setupKillcodeHeaders(c *gin.Context, req *http.Header) {
req.Set("anthropic-beta", anthropicBeta) req.Set("anthropic-beta", anthropicBeta)
} }
// 其他辅助头部 // 其他辅助头部 (移除可能导致问题的头部)
req.Set("accept-language", "*") 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) { func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.GeneralOpenAIRequest) (any, error) {