From 9ab5e0312dc644c55d5c5192c491d5bb585a162a Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Mon, 9 Aug 2021 21:45:59 +0200 Subject: [PATCH] Simplify gzhttp wrapper (#12912) The wrapper now accepts interfaces so we don't need a wrapper for that any more. --- cmd/admin-router.go | 15 ++++++--------- cmd/api-router.go | 14 +++++--------- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/cmd/admin-router.go b/cmd/admin-router.go index 095720919..bd41756d4 100644 --- a/cmd/admin-router.go +++ b/cmd/admin-router.go @@ -24,6 +24,7 @@ import ( "github.com/klauspost/compress/gzhttp" "github.com/klauspost/compress/gzip" "github.com/minio/madmin-go" + "github.com/minio/minio/internal/logger" ) const ( @@ -48,16 +49,12 @@ func registerAdminRouter(router *mux.Router, enableConfigOps bool) { adminAPIVersionPrefix, } - gz := func(h http.HandlerFunc) http.HandlerFunc { - return h + gz, err := gzhttp.NewWrapper(gzhttp.MinSize(1000), gzhttp.CompressionLevel(gzip.BestSpeed)) + if err != nil { + // Static params, so this is very unlikely. + logger.Fatal(err, "Unable to initialize server") } - wrapper, err := gzhttp.NewWrapper(gzhttp.MinSize(1000), gzhttp.CompressionLevel(gzip.BestSpeed)) - if err == nil { - gz = func(h http.HandlerFunc) http.HandlerFunc { - return wrapper(h).(http.HandlerFunc) - } - } for _, adminVersion := range adminVersions { // Restart and stop MinIO service. adminRouter.Methods(http.MethodPost).Path(adminVersion+"/service").HandlerFunc(gz(httpTraceAll(adminAPI.ServiceHandler))).Queries("action", "{action:.*}") @@ -207,7 +204,7 @@ func registerAdminRouter(router *mux.Router, enableConfigOps bool) { adminRouter.Methods(http.MethodPost).Path(adminVersion + "/speedtest").HandlerFunc(httpTraceHdrs(adminAPI.SpeedtestHandler)) // HTTP Trace - adminRouter.Methods(http.MethodGet).Path(adminVersion + "/trace").HandlerFunc(gz(adminAPI.TraceHandler)) + adminRouter.Methods(http.MethodGet).Path(adminVersion + "/trace").HandlerFunc(gz(http.HandlerFunc(adminAPI.TraceHandler))) // Console Logs adminRouter.Methods(http.MethodGet).Path(adminVersion + "/log").HandlerFunc(gz(httpTraceAll(adminAPI.ConsoleLogHandler))) diff --git a/cmd/api-router.go b/cmd/api-router.go index 5fbf48437..06bf91c4a 100644 --- a/cmd/api-router.go +++ b/cmd/api-router.go @@ -25,6 +25,7 @@ import ( "github.com/gorilla/mux" "github.com/klauspost/compress/gzhttp" xhttp "github.com/minio/minio/internal/http" + "github.com/minio/minio/internal/logger" "github.com/minio/pkg/wildcard" "github.com/rs/cors" ) @@ -208,15 +209,10 @@ func registerAPIRouter(router *mux.Router) { } routers = append(routers, apiRouter.PathPrefix("/{bucket}").Subrouter()) - gz := func(h http.HandlerFunc) http.HandlerFunc { - return h - } - - wrapper, err := gzhttp.NewWrapper(gzhttp.MinSize(1000), gzhttp.CompressionLevel(gzip.BestSpeed)) - if err == nil { - gz = func(h http.HandlerFunc) http.HandlerFunc { - return wrapper(h).(http.HandlerFunc) - } + gz, err := gzhttp.NewWrapper(gzhttp.MinSize(1000), gzhttp.CompressionLevel(gzip.BestSpeed)) + if err != nil { + // Static params, so this is very unlikely. + logger.Fatal(err, "Unable to initialize server") } for _, router := range routers { diff --git a/go.mod b/go.mod index b089a6a24..15e2dde2c 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/gorilla/mux v1.8.0 github.com/jcmturner/gokrb5/v8 v8.4.2 github.com/json-iterator/go v1.1.11 - github.com/klauspost/compress v1.13.1 + github.com/klauspost/compress v1.13.3 github.com/klauspost/cpuid/v2 v2.0.4 github.com/klauspost/pgzip v1.2.5 github.com/klauspost/readahead v1.3.1 diff --git a/go.sum b/go.sum index 42dad1f15..e6d5f2837 100644 --- a/go.sum +++ b/go.sum @@ -881,8 +881,8 @@ github.com/klauspost/compress v1.11.0/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYs github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.12/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= -github.com/klauspost/compress v1.13.1 h1:wXr2uRxZTJXHLly6qhJabee5JqIhTRoLBhDOA74hDEQ= -github.com/klauspost/compress v1.13.1/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/klauspost/compress v1.13.3 h1:BtAvtV1+h0YwSVwWoYXMREPpYu9VzTJ9QDI1TEg/iQQ= +github.com/klauspost/compress v1.13.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=