Skip to content

Commit 8c3dd3d

Browse files
authored
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
1 parent eddbccd commit 8c3dd3d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

modules/caddyhttp/requestbody/requestbody.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package requestbody
1616

1717
import (
18+
"errors"
1819
"io"
1920
"net/http"
2021
"time"
@@ -94,7 +95,8 @@ type errorWrapper struct {
9495

9596
func (ew errorWrapper) Read(p []byte) (n int, err error) {
9697
n, err = ew.ReadCloser.Read(p)
97-
if err != nil && err.Error() == "http: request body too large" {
98+
var mbe *http.MaxBytesError
99+
if errors.As(err, &mbe) {
98100
err = caddyhttp.Error(http.StatusRequestEntityTooLarge, err)
99101
}
100102
return

0 commit comments

Comments
 (0)