-
- Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Issue Description
The Echo Response object causes a panic when calling the Flush method with an unflushable parent writer.
For example, if you are using TimeoutMiddleware, which creates TimeoutHandler (github.com/labstack/echo/v4/middleware/timeout.go:124) and then creates a timeout writer (src/net/http/server.go:3584), and you try to call the Flush method in the echo.Context object, it will result in a panic. This happens because it doesn't check if the Writer implements the Flush method before calling it (github.com/labstack/echo/v4/response.go:87). This issue can be handled similarly to how the standard http library does it (httputil/reverseproxy.go:524).
I've noticed duplicated issues, but in my humble opinion, you should try to unpack writers and search for flushable ones, similar to how it's done in the standard library. What do you think?
Checklist
- Dependencies installed
- No typos
- Searched existing issues and docs
Expected behaviour
Calling Flush method with response writers that doesn't implements Flusher interface should not panicking
Actual behaviour
Calling Flush method with response writers that doesn't implements Flusher interface is panicking
Steps to reproduce
- Use timeout middleware
- Implement endpoint that call c.(echo.Context).Response().Flush() method
- Curl that endpoint
Working code to debug
func main() { e := echo.New() e.Use(middleware.TimeoutWithConfig(middleware.TimeoutConfig{ Timeout: 3 * time.Second, })) e.GET("/ping", func(c echo.Context) error { c.Response().Flush() return c.String(http.StatusOK, "pong") }) if err := e.Start(":8080"); err != nil { log.Fatalln(err.Error()) } }Version/commit
github.com/labstack/echo/v4 v4.11.4