fix: Filter out Accept-Encoding header in request passthrough to prevent compression

Fixed 'invalid character '\x1f' looking for beginning of value' error when sending images:
- Added accept-encoding to filtered headers in complete passthrough mode
- This prevents upstream from returning gzip compressed responses that new-api cannot parse
- Issue occurred when clients (like image uploads) had compression headers passed through directly

🤖 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:25:03 +08:00
parent 4f44976214
commit 9ad2c1f1bb

View File

@@ -65,10 +65,10 @@ func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Header, info *rel
// 智能请求头策略:检测客户端类型并决定处理方式
if isClaudeCode(userAgent) || isKillcode(userAgent) {
// Claude Code 和 killcode: 完全透传原始请求头
// Claude Code 和 killcode: 完全透传原始请求头 (除了压缩头)
for key, values := range c.Request.Header {
keyLower := strings.ToLower(key)
if keyLower == "host" || keyLower == "content-length" || keyLower == "connection" {
if keyLower == "host" || keyLower == "content-length" || keyLower == "connection" || keyLower == "accept-encoding" {
continue
}
for _, value := range values {