From e4fa6200c3c14dc51b5808dff5dc46f97b91cfef Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Thu, 12 Oct 2023 08:27:31 +0200 Subject: [PATCH] [MM-45309] Replace github.com/mattermost/gziphandler with github.com/klauspost/compress/gzhttp (#24293) --- server/channels/api4/handlers.go | 20 ++++++++++---------- server/channels/api4/post.go | 2 +- server/channels/web/handlers.go | 9 ++++----- server/channels/web/static.go | 6 +++--- server/go.mod | 3 +-- server/go.sum | 3 --- 6 files changed, 19 insertions(+), 24 deletions(-) diff --git a/server/channels/api4/handlers.go b/server/channels/api4/handlers.go index 62e20fd70e6..cb440c7f91d 100644 --- a/server/channels/api4/handlers.go +++ b/server/channels/api4/handlers.go @@ -6,7 +6,7 @@ package api4 import ( "net/http" - "github.com/mattermost/gziphandler" + "github.com/klauspost/compress/gzhttp" "github.com/mattermost/mattermost/server/public/model" "github.com/mattermost/mattermost/server/public/shared/mlog" @@ -32,7 +32,7 @@ func (api *API) APIHandler(h handlerFunc) http.Handler { IsLocal: false, } if *api.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } @@ -51,7 +51,7 @@ func (api *API) APISessionRequired(h handlerFunc) http.Handler { IsLocal: false, } if *api.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } @@ -70,7 +70,7 @@ func (api *API) CloudAPIKeyRequired(h handlerFunc) http.Handler { IsLocal: false, } if *api.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } @@ -90,7 +90,7 @@ func (api *API) RemoteClusterTokenRequired(h handlerFunc) http.Handler { IsLocal: false, } if *api.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } @@ -110,7 +110,7 @@ func (api *API) APISessionRequiredMfa(h handlerFunc) http.Handler { IsLocal: false, } if *api.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } @@ -130,7 +130,7 @@ func (api *API) APIHandlerTrustRequester(h handlerFunc) http.Handler { IsLocal: false, } if *api.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } @@ -149,7 +149,7 @@ func (api *API) APISessionRequiredTrustRequester(h handlerFunc) http.Handler { IsLocal: false, } if *api.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } @@ -169,7 +169,7 @@ func (api *API) APISessionRequiredDisableWhenBusy(h handlerFunc) http.Handler { DisableWhenBusy: true, } if *api.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } @@ -191,7 +191,7 @@ func (api *API) APILocal(h handlerFunc) http.Handler { } if *api.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } diff --git a/server/channels/api4/post.go b/server/channels/api4/post.go index cb7ad741fc0..64a0d4eb4fc 100644 --- a/server/channels/api4/post.go +++ b/server/channels/api4/post.go @@ -658,7 +658,7 @@ func getPostThread(c *Context, w http.ResponseWriter, r *http.Request) { fromPost := r.URL.Query().Get("fromPost") // Either only fromCreateAt must be set, or both fromPost and fromCreateAt must be set if fromPost != "" && fromCreateAt == 0 { - c.SetInvalidParam("if fromPost is set, then fromCreatAt must also be set") + c.SetInvalidParam("if fromPost is set, then fromCreateAt must also be set") return } diff --git a/server/channels/web/handlers.go b/server/channels/web/handlers.go index 0adb2c6aace..0b97e270b58 100644 --- a/server/channels/web/handlers.go +++ b/server/channels/web/handlers.go @@ -14,12 +14,11 @@ import ( "strings" "time" + "github.com/klauspost/compress/gzhttp" "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" spanlog "github.com/opentracing/opentracing-go/log" - "github.com/mattermost/gziphandler" - "github.com/mattermost/mattermost/server/public/model" "github.com/mattermost/mattermost/server/public/shared/i18n" "github.com/mattermost/mattermost/server/public/shared/mlog" @@ -474,7 +473,7 @@ func (w *Web) APIHandler(h func(*Context, http.ResponseWriter, *http.Request)) h IsLocal: false, } if *w.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } @@ -494,7 +493,7 @@ func (w *Web) APIHandlerTrustRequester(h func(*Context, http.ResponseWriter, *ht IsLocal: false, } if *w.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } @@ -513,7 +512,7 @@ func (w *Web) APISessionRequired(h func(*Context, http.ResponseWriter, *http.Req IsLocal: false, } if *w.srv.Config().ServiceSettings.WebserverMode == "gzip" { - return gziphandler.GzipHandler(handler) + return gzhttp.GzipHandler(handler) } return handler } diff --git a/server/channels/web/static.go b/server/channels/web/static.go index baa80b09b8c..011cbc889df 100644 --- a/server/channels/web/static.go +++ b/server/channels/web/static.go @@ -13,7 +13,7 @@ import ( "path/filepath" "strings" - "github.com/mattermost/gziphandler" + "github.com/klauspost/compress/gzhttp" "github.com/mattermost/mattermost/server/public/model" "github.com/mattermost/mattermost/server/public/shared/mlog" @@ -39,8 +39,8 @@ func (w *Web) InitStatic() { pluginHandler := staticFilesHandler(http.StripPrefix(path.Join(subpath, "static", "plugins"), http.FileServer(http.Dir(*w.srv.Config().PluginSettings.ClientDirectory)))) if *w.srv.Config().ServiceSettings.WebserverMode == "gzip" { - staticHandler = gziphandler.GzipHandler(staticHandler) - pluginHandler = gziphandler.GzipHandler(pluginHandler) + staticHandler = gzhttp.GzipHandler(staticHandler) + pluginHandler = gzhttp.GzipHandler(pluginHandler) } w.MainRouter.PathPrefix("/static/plugins/").Handler(pluginHandler) diff --git a/server/go.mod b/server/go.mod index cec181adfc5..4a84441e285 100644 --- a/server/go.mod +++ b/server/go.mod @@ -31,10 +31,10 @@ require ( github.com/isacikgoz/prompt v0.1.0 github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 github.com/jmoiron/sqlx v1.3.5 + github.com/klauspost/compress v1.16.6 github.com/ledongthuc/pdf v0.0.0-20220302134840-0c2507a12d80 github.com/lib/pq v1.10.9 github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 - github.com/mattermost/gziphandler v0.0.1 github.com/mattermost/logr/v2 v2.0.18 github.com/mattermost/mattermost/server/public v0.0.9 github.com/mattermost/morph v1.0.5-0.20230511171014-e76e25978d56 @@ -131,7 +131,6 @@ require ( github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect - github.com/klauspost/compress v1.16.6 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/klauspost/pgzip v1.2.6 // indirect github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect diff --git a/server/go.sum b/server/go.sum index 65a761dc0fa..6b5f0aec202 100644 --- a/server/go.sum +++ b/server/go.sum @@ -401,7 +401,6 @@ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:C github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.13.1/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= github.com/klauspost/compress v1.16.6 h1:91SKEy4K37vkp255cJ8QesJhjyRO0hn9i9G0GoUwLsk= github.com/klauspost/compress v1.16.6/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= @@ -437,8 +436,6 @@ github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3v github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 h1:Khvh6waxG1cHc4Cz5ef9n3XVCxRWpAKUtqg9PJl5+y8= github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404/go.mod h1:RyS7FDNQlzF1PsjbJWHRI35exqaKGSO9qD4iv8QjE34= -github.com/mattermost/gziphandler v0.0.1 h1:uXHcXF5agnQ6bXabvpiwwwZOlCYoa7mKHH0lxns/o8w= -github.com/mattermost/gziphandler v0.0.1/go.mod h1:CvvZR7sXqhj81V2swXuQY7T04Ccc89u7W7pHNPKev8g= github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d h1:/RJ/UV7M5c7L2TQ0KNm4yZxxFvC1nvRz/gY/Daa35aI= github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d/go.mod h1:HLbgMEI5K131jpxGazJ97AxfPDt31osq36YS1oxFQPQ= github.com/mattermost/logr/v2 v2.0.18 h1:qiznuwwKckZJoGtBYc4Y9FAY97/oQwV1Pq9oO5qP5nk=