Add X-Syncthing-Version header to HTTP responses

This commit is contained in:
Jakob Borg 2014-08-31 12:59:20 +02:00
parent c2120a16da
commit c326103e6e
1 changed files with 10 additions and 0 deletions

View File

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