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
This commit is contained in:
Jesse Hallam
2018-07-31 16:29:52 -04:00
committed by GitHub
parent 8c56f52d17
commit 0788cdcadf
5 changed files with 58 additions and 54 deletions

View File

@@ -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)
})
}