Ir al contenido

Body Dump

El middleware Body Dump captura los payloads de request y response y los pasa a un handler registrado. Generalmente se usa para debugging o logging.

Todo el middleware principal reside en el paquete 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.
}))
e := echo.New()
e.Use(middleware.BodyDumpWithConfig(middleware.BodyDumpConfig{}))

BodyDumpConfig · github.com/labstack/echo/[email protected]

Las descripciones de los campos se generan a partir de comentarios del código fuente en inglés.

Campos del código fuente
CampoTipoDescripciónFuente
SkipperSkipperSkipper defines a function to skip middleware.L21
HandlerBodyDumpHandlerHandler receives request, response payloads and handler error if there are any. Required.L25
MaxRequestBytesint64MaxRequestBytes 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. Default: 5 * MB (5,242,880 bytes) Set to -1 to disable limits (not recommended in production).L32
MaxResponseBytesint64MaxResponseBytes 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).L39
Funciones del código fuente
TipoFuente
func BodyDump(handler BodyDumpHandler) echo.MiddlewareFuncL58
func BodyDumpWithConfig(config BodyDumpConfig) echo.MiddlewareFuncL68

Handler tiene esta firma:

type BodyDumpHandler func(c *echo.Context, reqBody []byte, resBody []byte, err error)
// Effective defaults applied when fields are left unset (Handler is required).
BodyDumpConfig{
Skipper: DefaultSkipper,
MaxRequestBytes: 5 * MB,
MaxResponseBytes: 5 * MB,
}