ekko: gzip config option

This commit is contained in:
Ask Bjørn Hansen 2024-12-01 16:45:49 -08:00
parent 68bd4d8904
commit b926a85737
2 changed files with 13 additions and 1 deletions

View File

@ -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()) e.Use(middleware.Secure())

View File

@ -4,6 +4,7 @@ import (
"time" "time"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
slogecho "github.com/samber/slog-echo" slogecho "github.com/samber/slog-echo"
) )
@ -15,6 +16,7 @@ type Ekko struct {
routeFn func(e *echo.Echo) error routeFn func(e *echo.Echo) error
logFilters []slogecho.Filter logFilters []slogecho.Filter
otelmiddleware echo.MiddlewareFunc otelmiddleware echo.MiddlewareFunc
gzipConfig *middleware.GzipConfig
writeTimeout time.Duration writeTimeout time.Duration
readHeaderTimeout time.Duration readHeaderTimeout time.Duration
@ -63,3 +65,9 @@ func WithReadHeaderTimeout(t time.Duration) func(*Ekko) {
ek.readHeaderTimeout = t ek.readHeaderTimeout = t
} }
} }
func WithGzipConfig(gzipConfig *middleware.GzipConfig) func(*Ekko) {
return func(ek *Ekko) {
ek.gzipConfig = gzipConfig
}
}