26 lines
625 B
Go
26 lines
625 B
Go
// 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()
|
|
}
|
|
}
|