diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index ed43ce098..b92f1706b 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -145,6 +145,9 @@ func startGUI(cfg config.GUIConfiguration, assetDir string, m *model.Model) erro // protected, other requests will grant cookies. handler := csrfMiddleware("/rest", mux) + // Add our version as a header to responses + handler = withVersionMiddleware(handler) + // Wrap everything in basic auth, if user/password is set. if len(cfg.User) > 0 { handler = basicAuthMiddleware(cfg.User, cfg.Password, handler) @@ -174,6 +177,13 @@ func noCacheMiddleware(h http.Handler) http.Handler { }) } +func withVersionMiddleware(h http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("X-Syncthing-Version", Version) + h.ServeHTTP(w, r) + }) +} + func withModel(m *model.Model, h func(m *model.Model, w http.ResponseWriter, r *http.Request)) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { h(m, w, r)