From 0788cdcadfb5d76b08758f42f01521b45ea76362 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Tue, 31 Jul 2018 16:29:52 -0400 Subject: MM-11420: plugins: compute bundle hash on load (#9172) * plugins: compute bundle hash on load Use this hash to bust client caches whenever the plugin bundle changes. * eliminate redundant pluginHandler * switch to 64-bit FNV-1a * Fix test --- web/static.go | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'web') diff --git a/web/static.go b/web/static.go index 7c1d37252..64d326e24 100644 --- a/web/static.go +++ b/web/static.go @@ -29,8 +29,8 @@ func (w *Web) InitStatic() { mime.AddExtensionType(".wasm", "application/wasm") - staticHandler := staticHandler(http.StripPrefix(path.Join(subpath, "static"), http.FileServer(http.Dir(staticDir)))) - pluginHandler := pluginHandler(w.App.Config, http.StripPrefix(path.Join(subpath, "static", "plugins"), http.FileServer(http.Dir(*w.App.Config().PluginSettings.ClientDirectory)))) + staticHandler := staticFilesHandler(http.StripPrefix(path.Join(subpath, "static"), http.FileServer(http.Dir(staticDir)))) + pluginHandler := staticFilesHandler(http.StripPrefix(path.Join(subpath, "static", "plugins"), http.FileServer(http.Dir(*w.App.Config().PluginSettings.ClientDirectory)))) if *w.App.Config().ServiceSettings.WebserverMode == "gzip" { staticHandler = gziphandler.GzipHandler(staticHandler) @@ -72,7 +72,7 @@ func root(c *Context, w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, filepath.Join(staticDir, "root.html")) } -func staticHandler(handler http.Handler) http.Handler { +func staticFilesHandler(handler http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "max-age=31556926, public") if strings.HasSuffix(r.URL.Path, "/") { @@ -82,18 +82,3 @@ func staticHandler(handler http.Handler) http.Handler { handler.ServeHTTP(w, r) }) } - -func pluginHandler(config model.ConfigFunc, handler http.Handler) http.Handler { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if *config().ServiceSettings.EnableDeveloper { - w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") - } else { - w.Header().Set("Cache-Control", "max-age=31556926, public") - } - if strings.HasSuffix(r.URL.Path, "/") { - http.NotFound(w, r) - return - } - handler.ServeHTTP(w, r) - }) -} -- cgit v1.2.3-1-g7c22