MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / MaxBody

Function MaxBody

pkg/webmiddleware/max_body.go:25–38  ·  view source on GitHub ↗

MaxBody returns a middleware that limits the maximum body of requests.

(maxBytes int64)

Source from the content-addressed store, hash-verified

23
24// MaxBody returns a middleware that limits the maximum body of requests.
25func MaxBody(maxBytes int64) MiddlewareFunc {
26 return func(next http.Handler) http.Handler {
27 if maxBytes == 0 {
28 return next
29 }
30 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
31 r.Body = &wrappedMaxBytesReader{
32 ReadCloser: http.MaxBytesReader(w, r.Body, maxBytes),
33 maxBytes: maxBytes,
34 }
35 next.ServeHTTP(w, r)
36 })
37 }
38}
39
40// NOTE: Ideally this would translate to a HTTP 413 error code,
41// but we can't represent those at the moment.

Callers 4

NewFunction · 0.92
NewServerFunction · 0.92
NewFunction · 0.92
TestMaxBodyFunction · 0.85

Calls 1

ServeHTTPMethod · 0.45

Tested by 1

TestMaxBodyFunction · 0.68