1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

requestbody: Type-based error handling for MaxBytesError (#6701)

* fix: handle "request body too large" error using type assertion

* fix: address overlooked nil check for MaxBytesError

* fix: replace type assertion with errors.As() for MaxBytesError
This commit is contained in:
Rishita Shaw 2024-11-23 01:15:58 +05:30 committed by GitHub
parent eddbccd298
commit 8c3dd3de70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,6 +15,7 @@
package requestbody package requestbody
import ( import (
"errors"
"io" "io"
"net/http" "net/http"
"time" "time"
@ -94,7 +95,8 @@ type errorWrapper struct {
func (ew errorWrapper) Read(p []byte) (n int, err error) { func (ew errorWrapper) Read(p []byte) (n int, err error) {
n, err = ew.ReadCloser.Read(p) n, err = ew.ReadCloser.Read(p)
if err != nil && err.Error() == "http: request body too large" { var mbe *http.MaxBytesError
if errors.As(err, &mbe) {
err = caddyhttp.Error(http.StatusRequestEntityTooLarge, err) err = caddyhttp.Error(http.StatusRequestEntityTooLarge, err)
} }
return return