summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorJesse Hallam <jesse.hallam@gmail.com>2018-07-31 16:29:52 -0400
committerGitHub <noreply@github.com>2018-07-31 16:29:52 -0400
commit0788cdcadfb5d76b08758f42f01521b45ea76362 (patch)
tree86efb424a0543571398866e3cb84ee38be101141 /web
parent8c56f52d17d73a431a060919c97fe8939f81a0d1 (diff)
downloadchat-0788cdcadfb5d76b08758f42f01521b45ea76362.tar.gz
chat-0788cdcadfb5d76b08758f42f01521b45ea76362.tar.bz2
chat-0788cdcadfb5d76b08758f42f01521b45ea76362.zip
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
Diffstat (limited to 'web')
-rw-r--r--web/static.go21
1 files changed, 3 insertions, 18 deletions
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)
- })
-}