Documentation ¶
Overview ¶
Package limitbytes implements a middleware to enforce limits on the http request body size.
This is a thin wrapper around `http.MaxBytesReader`. This fails the request early before reading data if content-length is known, otherwise returns a custom error type `ErrTooLarge` by parsing the error from `http.MaxBytesReader`. This also sets the response code to 413 (`http.StatusRequestEntityTooLarge`).
An optional callback can be provided to handle failure case (but this only works if the content-length is available).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(n int64, callback func(http.ResponseWriter, *http.Request, error)) func(next http.Handler) http.Handler
New is a middleware that limits the request body size to n bytes by wrapping the request body using http.MaxBytesReader. If content-length is available, this fails early without calling the next handler. An optional callback can be passed in which is called if content-length is available and request size is greater than n.
Types ¶
type ErrTooLarge ¶
type ErrTooLarge struct {
Err error // underlying error
}
ErrTooLarge error is used to indicate that the request size is too large
func (ErrTooLarge) Error ¶
func (r ErrTooLarge) Error() string