feat: release v0.27 unified HTTP limits and safe request shutdown
This commit is contained in:
25
internal/httplimits/limits.go
Normal file
25
internal/httplimits/limits.go
Normal 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user