-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support sendfile when echo is static file server #2725
Comments
you can verify this with package main
import (
"errors"
"github.com/labstack/echo/v4"
"io"
"log/slog"
"net/http"
)
func main() {
e := echo.New()
e.GET("/", func(c echo.Context) error {
_, ok := c.Response().Writer.(io.ReaderFrom)
if ok {
return c.JSON(http.StatusOK, "implements io.ReaderFrom")
}
return c.JSON(http.StatusOK, "nope")
})
if err := e.Start(":8080"); err != nil && !errors.Is(err, http.ErrServerClosed) {
slog.Error("failed to start server", "error", err)
}
} |
http. ResponseWriter implements io ReaderFrom interface, so go SDK can support sendfile, but echo.Response not implemented, you can debug the code to see if the io.CpyBuffer method line cannot be converted, thus unable to use sendfile
|
ok, I see. we are talking about this place in Echo Lines 243 to 246 in 45524e3
maybe changing from http.ServeContent(c.Response(), c.Request(), info.Name(), info.ModTime(), file) to http.ServeContent(c.Response().Writer, c.Request(), info.Name(), info.ModTime(), file) would be enough |
Issue Description
Response should implement io.ReaderFrom interface, only when used as a static file server can the sendfile function be used
Working code to debug
Version/commit
The text was updated successfully, but these errors were encountered: