feat: release v0.27 unified HTTP limits and safe request shutdown

This commit is contained in:
2026-09-29 23:24:19 +08:00
parent 859f1851b1
commit 3b00bb55d1
42 changed files with 1191 additions and 70 deletions

View File

@@ -0,0 +1,25 @@
// Package httplimits shares the application body policy across transports.
package httplimits
import "net/http"
const (
DefaultBodyBytes int64 = 8 << 20
MaxBodyBytes int64 = 1 << 40
)
// RejectBody tells cooperating transports not to drain a rejected body. The
// semantic failure must survive encoders that map business failures to HTTP 200.
func RejectBody(w http.ResponseWriter) {
for {
if reject, ok := w.(interface{ RequestBodyTooLarge() }); ok {
reject.RequestBodyTooLarge()
return
}
unwrap, ok := w.(interface{ Unwrap() http.ResponseWriter })
if !ok {
return
}
w = unwrap.Unwrap()
}
}