Body Dump
O middleware Body Dump captura os payloads de request e response e os passa para um handler registrado. Em geral, ele é usado para debugging ou logging.
Todo o middleware principal fica no pacote middleware:
import "github.com/labstack/echo/v5/middleware"e := echo.New()e.Use(middleware.BodyDump(func(c *echo.Context, reqBody, resBody []byte, err error) { // Handle the request and response bodies.}))Configuração customizada
Seção intitulada “Configuração customizada”e := echo.New()e.Use(middleware.BodyDumpWithConfig(middleware.BodyDumpConfig{}))Configuração
Seção intitulada “Configuração”BodyDumpConfig · github.com/labstack/echo/[email protected]
As descrições dos campos são geradas dos comentários do código-fonte em inglês.
| Campo | Tipo | Descrição | Código |
|---|---|---|---|
Skipper | Skipper | Skipper defines a function to skip middleware. | L21 |
Handler | BodyDumpHandler | Handler receives request, response payloads and handler error if there are any. Required. | L25 |
MaxRequestBytes | int64 | MaxRequestBytes limits how much of the request body to dump. If the request body exceeds this limit, only the first MaxRequestBytes are dumped. The handler callback receives truncated data. The next handler still receives the full request body. Default: 5 * MB (5,242,880 bytes) Set to -1 to disable limits (not recommended in production). | L33 |
MaxResponseBytes | int64 | MaxResponseBytes limits how much of the response body to dump. If the response body exceeds this limit, only the first MaxResponseBytes are dumped. The handler callback receives truncated data. Default: 5 * MB (5,242,880 bytes) Set to -1 to disable limits (not recommended in production). | L40 |
O Handler tem a assinatura:
type BodyDumpHandler func(c *echo.Context, reqBody []byte, resBody []byte, err error)Configuração padrão
Seção intitulada “Configuração padrão”// Effective defaults applied when fields are left unset (Handler is required).BodyDumpConfig{ Skipper: DefaultSkipper, MaxRequestBytes: 5 * MB, MaxResponseBytes: 5 * MB,}