aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRishita Shaw <[email protected]>2024-11-23 01:15:58 +0530
committerGitHub <[email protected]>2024-11-22 19:45:58 +0000
commit8c3dd3de709040d72bd98a756a044c453d7e871e (patch)
tree4eb172f304134adc223760088b97fb8091438cd9
parenteddbccd298f637c4785c891f5f96dbf103580fa8 (diff)
downloadcaddy-8c3dd3de709040d72bd98a756a044c453d7e871e.tar.gz
caddy-8c3dd3de709040d72bd98a756a044c453d7e871e.zip
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
-rw-r--r--modules/caddyhttp/requestbody/requestbody.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/modules/caddyhttp/requestbody/requestbody.go b/modules/caddyhttp/requestbody/requestbody.go
index 1c804aa13..830050416 100644
--- a/modules/caddyhttp/requestbody/requestbody.go
+++ b/modules/caddyhttp/requestbody/requestbody.go
@@ -15,6 +15,7 @@
package requestbody
import (
+ "errors"
"io"
"net/http"
"time"
@@ -94,7 +95,8 @@ type errorWrapper struct {
func (ew errorWrapper) Read(p []byte) (n int, err error) {
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)
}
return