fix: unify MAX_REQUEST_BODY_MB defaults and fallback handling - #3341
fix: unify MAX_REQUEST_BODY_MB defaults and fallback handling#3341Honghurumeng wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
WalkthroughThis PR refactors the request body size limit logic by centralizing the default value handling. A new constant Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can approve the review once all CodeRabbit's comments are resolved.Enable the |
This comment was marked as spam.
This comment was marked as spam.
51fdfc5 to
2b6f1df
Compare
Summary
统一
MAX_REQUEST_BODY_MB的默认值与兜底逻辑,修正文档和运行时行为不一致的问题当前项目中,
MAX_REQUEST_BODY_MB在文档、初始化代码以及请求体处理链路中的默认值和<= 0兜底行为并不一致。本 PR 将这些逻辑统一为
128MB,避免出现配置无效时不同链路执行结果不一致的问题。我在实际使用中128MB不够用,一直改到512MB才实现codex auto compact,但是考虑这个值能作为环境变量修改,就保持了128MB。
Background
项目中的请求体大小限制由环境变量
MAX_REQUEST_BODY_MB控制,但此前存在两类不一致:文档默认值与代码默认值不一致
MAX_REQUEST_BODY_MB默认值写为32128MAX_REQUEST_BODY_MB <= 0时兜底行为不一致32MB128MB由于解压中间件和请求体读取逻辑都在实际请求链路中生效,这种不一致会导致配置为
0、负数或依赖默认值时,系统表现不稳定,也容易让文档使用者产生误解。本 PR 统一了默认值来源和兜底逻辑,使其在所有相关代码路径中保持一致。
Changes
constant/env.go新增共享默认值常量与统一兜底函数:
DefaultMaxRequestBodyMB = 128EffectiveMaxRequestBodyMB(),用于统一处理<= 0时回退到默认值的逻辑common/init.go统一初始化默认值来源:
MAX_REQUEST_BODY_MB的初始化默认值改为引用constant.DefaultMaxRequestBodyMBmiddleware/gzip.go统一请求解压/入口限制逻辑:
constant.EffectiveMaxRequestBodyMB()获取有效限制值32MB作为<= 0的兜底值common/gin.go统一请求体读取与缓存限制逻辑:
constant.EffectiveMaxRequestBodyMB()获取有效限制值128MB回退逻辑README.md修正文档默认值:
MAX_REQUEST_BODY_MB的默认值从32更新为128constant/env_test.go新增测试覆盖:
0时回退到默认值128128Testing
gofmt格式化相关 Go 文件go test ./constant ./common ./middlewareconstant包测试通过common包测试通过middleware包当前无测试文件Summary by CodeRabbit
Documentation
Refactor