echo icon indicating copy to clipboard operation
echo copied to clipboard

Undocumented limitation on BodyDumpConfig Skipper in BodyDump middleware

Open betaprior opened this issue 4 years ago • 1 comments

Issue Description

Documentation suggests using the skipper function to skip over large response bodies. However, it is not obvious that the skipper function runs before the route handler, which makes it rather useless in a lot of common cases. In particular, it is useless if I want to skip the middleware for a specific content type (e.g. binary download), as the header will be set after the skipper runs.

The solution is very simple -- don't use the skipper function and put the skipping logic in the body dump handler. It would be nice if the documentation mentioned that.

Version/commit

Echo 4.5

betaprior avatar Sep 24 '21 08:09 betaprior

I would assume that part in docs was referring to cases when you know body to be not worthy to be logged. ala you want to log usual API endpoints but exclude certain binary download paths.

If someone has better wording for that, please do PR against that file https://github.com/labstack/echox/blob/master/website/content/middleware/body-dump.md in Echox repository

aldas avatar Sep 26 '21 15:09 aldas

closing at the moment.

  • BodyDumpConfig.Skipper allows user to skip reading request/response body to memory altogether.
  • BodyDumpConfig.Handler takes in echo.Context, request body, response body so user can decide on c.Response() values if req/res needs to be dumped.

aldas avatar Dec 03 '23 17:12 aldas