From b926a857378bc5206172aa1578f8976facbec576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Sun, 1 Dec 2024 16:45:49 -0800 Subject: [PATCH] ekko: gzip config option --- ekko/ekko.go | 6 +++++- ekko/options.go | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ekko/ekko.go b/ekko/ekko.go index ddb6a13..899c33f 100644 --- a/ekko/ekko.go +++ b/ekko/ekko.go @@ -114,7 +114,11 @@ func (ek *Ekko) setup(ctx context.Context) (*echo.Echo, error) { })) } - e.Use(middleware.Gzip()) + if ek.gzipConfig != nil { + e.Use(middleware.GzipWithConfig(*ek.gzipConfig)) + } else { + e.Use(middleware.Gzip()) + } e.Use(middleware.Secure()) diff --git a/ekko/options.go b/ekko/options.go index 9dd38f3..d06df59 100644 --- a/ekko/options.go +++ b/ekko/options.go @@ -4,6 +4,7 @@ import ( "time" "github.com/labstack/echo/v4" + "github.com/labstack/echo/v4/middleware" "github.com/prometheus/client_golang/prometheus" slogecho "github.com/samber/slog-echo" ) @@ -15,6 +16,7 @@ type Ekko struct { routeFn func(e *echo.Echo) error logFilters []slogecho.Filter otelmiddleware echo.MiddlewareFunc + gzipConfig *middleware.GzipConfig writeTimeout time.Duration readHeaderTimeout time.Duration @@ -63,3 +65,9 @@ func WithReadHeaderTimeout(t time.Duration) func(*Ekko) { ek.readHeaderTimeout = t } } + +func WithGzipConfig(gzipConfig *middleware.GzipConfig) func(*Ekko) { + return func(ek *Ekko) { + ek.gzipConfig = gzipConfig + } +}