Browse Source

Merge pull request #104 from filoozom/patch-2

Set cache control on /rest/* (fixes #95)
Jakob Borg 11 years ago
parent
commit
e37441627f
1 changed files with 7 additions and 0 deletions
  1. 7 0
      cmd/syncthing/gui.go

+ 7 - 0
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
 }