@marcel91200 / caddy Mirror · read-only / commits / 8c3dd3de
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 05:45 UTC

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

Rishita Shaw committed Nov 23, 2024 at 01:15 UTC 8c3dd3de709040d72bd98a756a044c453d7e871e
1 file changed +3 -1
modules/caddyhttp/requestbody/requestbody.go
+3 -1
@@ -15,6 +15,7 @@
15 package requestbody
16
17 import (
18 + "errors"
19 "io"
20 "net/http"
21 "time"
@@ -94,7 +95,8 @@ type errorWrapper struct {
95
96 func (ew errorWrapper) Read(p []byte) (n int, err error) {
97 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) {
100 err = caddyhttp.Error(http.StatusRequestEntityTooLarge, err)
101 }
102 return