From f4c6cd1676cf2a7dc3a4aff5398c7162df4b80cf Mon Sep 17 00:00:00 2001 From: Philippe Schommers Date: Wed, 26 Mar 2014 20:32:35 +0100 Subject: [PATCH] Set cache control on /rest/* (fixes #95) Disable caching for all /rest/* requests. --- cmd/syncthing/gui.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index e25508b38..53d9f01ae 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -44,6 +44,7 @@ func startGUI(addr string, m *Model) { mr := martini.New() mr.Use(embeddedStatic()) mr.Use(martini.Recovery()) + mr.Use(restMiddleware) mr.Action(router.Handle) mr.Map(m) err := http.ListenAndServe(addr, mr) @@ -57,6 +58,12 @@ func getRoot(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/index.html", 302) } +func restMiddleware(w http.ResponseWriter, r *http.Request) { + if len(r.URL.Path) >= 6 && r.URL.Path[:6] == "/rest/" { + w.Header().Set("Cache-Control", "no-cache") + } +} + func restGetVersion() string { return Version }