增加安全字段校验提示、请求预算和就绪/存活探针, 让绑定、数据库、Redis 和出站响应解码保留可信诊断上下文。 补充完整应用装配及逆序清理示例,同步接入和迁移文档。 验证:make verify、make race-check 全部通过。 BREAKING CHANGE: 普通 Controller 默认启用 30 秒协作式请求预算, 可用 request_timeout_ms: 0 或 max-exec-time:"0" 关闭; 字段校验失败的 400 响应增加安全字段明细。
This commit is contained in:
1 parent
b4c3ac622c
commit
3196e45a01
22 files changed
+1294
-79
No files matched your search
@@ -24,18 +24,18 @@ const (
|
||||
// 返回:正文副本视图;失败保留读取错误或 http.MaxBytesError 原因链。
|
||||
func ReadBodyWithLimit(ctx *gin.Context, limit int64) ([]byte, error) {
|
||||
if ctx == nil || ctx.Request == nil {
|
||||
return nil, fault.Wrap(codeBodyContext, "validate request body context failed", errors.New("request context is missing"))
|
||||
return nil, fault.WrapContext(contextOf(ctx), codeBodyContext, "validate request body context failed", errors.New("request context is missing"))
|
||||
}
|
||||
if limit <= 0 {
|
||||
limit = DefaultMaxBodyBytes
|
||||
}
|
||||
if limit == 1<<63-1 {
|
||||
return nil, fault.Wrap(codeBodyLarge, "validate request body limit failed", errors.New("body limit exceeds supported range"))
|
||||
return nil, fault.WrapContext(contextOf(ctx), codeBodyLarge, "validate request body limit failed", errors.New("body limit exceeds supported range"))
|
||||
}
|
||||
if cached, exists := ctx.Get(bodyCacheKey); exists {
|
||||
body := cached.([]byte)
|
||||
if int64(len(body)) > limit {
|
||||
return nil, fault.Wrap(codeBodyLarge, "validate request body size failed", &http.MaxBytesError{Limit: limit})
|
||||
return nil, fault.WrapContext(contextOf(ctx), codeBodyLarge, "validate request body size failed", &http.MaxBytesError{Limit: limit})
|
||||
}
|
||||
ctx.Request.Body = io.NopCloser(bytes.NewReader(body))
|
||||
return body, nil
|
||||
@@ -49,10 +49,10 @@ func ReadBodyWithLimit(ctx *gin.Context, limit int64) ([]byte, error) {
|
||||
_ = original.Close()
|
||||
ctx.Request.Body = io.NopCloser(bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return nil, fault.Wrap(codeBodyRead, "read request body failed", err)
|
||||
return nil, fault.WrapContext(contextOf(ctx), codeBodyRead, "read request body failed", err)
|
||||
}
|
||||
if int64(len(body)) > limit {
|
||||
return nil, fault.Wrap(codeBodyLarge, "validate request body size failed", &http.MaxBytesError{Limit: limit})
|
||||
return nil, fault.WrapContext(contextOf(ctx), codeBodyLarge, "validate request body size failed", &http.MaxBytesError{Limit: limit})
|
||||
}
|
||||
ctx.Set(bodyCacheKey, body)
|
||||
return body, nil
|
||||
|
||||