feat(gateway): raise upstream non-streaming response read limit to 64MB

非流式上游响应读取上限从 8MB 提到 64MB,避免图片生成(image_generation_call
返回 base64 内联图)单张高清图就把响应撑爆、被 `ReadUpstreamResponseBody`
直接拒绝成 upstream_error 502。

64MB ≈ 48MB 原始字节(base64 膨胀 33%),足够一次响应带多张高清图。依然通过
gateway.upstream_response_read_max_bytes 可配置。
This commit is contained in:
erio
2026-04-17 18:32:33 +08:00
parent 93efc12812
commit c3fcc37cc4
2 changed files with 5 additions and 2 deletions
+1 -1
View File
@@ -1407,7 +1407,7 @@ func setDefaults() {
viper.SetDefault("gateway.antigravity_fallback_cooldown_minutes", 1)
viper.SetDefault("gateway.antigravity_extra_retries", 10)
viper.SetDefault("gateway.max_body_size", int64(256*1024*1024))
viper.SetDefault("gateway.upstream_response_read_max_bytes", int64(8*1024*1024))
viper.SetDefault("gateway.upstream_response_read_max_bytes", int64(64*1024*1024))
viper.SetDefault("gateway.proxy_probe_response_read_max_bytes", int64(1024*1024))
viper.SetDefault("gateway.gemini_debug_response_headers", false)
viper.SetDefault("gateway.connection_pool_isolation", ConnectionPoolIsolationAccountProxy)
@@ -12,7 +12,10 @@ import (
var ErrUpstreamResponseBodyTooLarge = errors.New("upstream response body too large")
const defaultUpstreamResponseReadMaxBytes int64 = 8 * 1024 * 1024
// defaultUpstreamResponseReadMaxBytes 上游非流式响应体的默认读取上限。
// 64 MB 足以容纳多张高清图(base64 膨胀 33%,64MB ≈ 48MB 原始字节)。
// 可通过 gateway.upstream_response_read_max_bytes 配置项覆盖。
const defaultUpstreamResponseReadMaxBytes int64 = 64 * 1024 * 1024
func resolveUpstreamResponseReadLimit(cfg *config.Config) int64 {
if cfg != nil && cfg.Gateway.UpstreamResponseReadMaxBytes > 0 {