File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed
Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package middleware
66import (
77 "fmt"
88 "io"
9+ "net/http"
910 "sync"
1011
1112 "github.com/labstack/echo/v4"
@@ -77,7 +78,10 @@ func BodyLimitWithConfig(config BodyLimitConfig) echo.MiddlewareFunc {
7778 }
7879
7980 // Based on content read
80- r := pool .Get ().(* limitedReader )
81+ r , ok := pool .Get ().(* limitedReader )
82+ if ! ok {
83+ return echo .NewHTTPError (http .StatusInternalServerError , "invalid pool object" )
84+ }
8185 r .Reset (req .Body )
8286 defer pool .Put (r )
8387 req .Body = r
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ func GzipWithConfig(config GzipConfig) echo.MiddlewareFunc {
9696 i := pool .Get ()
9797 w , ok := i .(* gzip.Writer )
9898 if ! ok {
99- return echo .NewHTTPError (http .StatusInternalServerError , i .( error ). Error () )
99+ return echo .NewHTTPError (http .StatusInternalServerError , "invalid pool object" )
100100 }
101101 rw := res .Writer
102102 w .Reset (rw )
@@ -189,7 +189,9 @@ func (w *gzipResponseWriter) Flush() {
189189 w .Writer .Write (w .buffer .Bytes ())
190190 }
191191
192- w .Writer .(* gzip.Writer ).Flush ()
192+ if gw , ok := w .Writer .(* gzip.Writer ); ok {
193+ gw .Flush ()
194+ }
193195 _ = http .NewResponseController (w .ResponseWriter ).Flush ()
194196}
195197
Original file line number Diff line number Diff line change @@ -284,7 +284,7 @@ func TestGzipErrorReturnedInvalidConfig(t *testing.T) {
284284 rec := httptest .NewRecorder ()
285285 e .ServeHTTP (rec , req )
286286 assert .Equal (t , http .StatusInternalServerError , rec .Code )
287- assert .Contains (t , rec .Body .String (), "gzip" )
287+ assert .Contains (t , rec .Body .String (), `{"message":"invalid pool object"}` )
288288}
289289
290290// Issue #806
You can’t perform that action at this time.
0 commit comments