Add X-Syncthing-Version header to HTTP responses
This commit is contained in:
parent
c2120a16da
commit
c326103e6e
|
@ -145,6 +145,9 @@ func startGUI(cfg config.GUIConfiguration, assetDir string, m *model.Model) erro
|
||||||
// protected, other requests will grant cookies.
|
// protected, other requests will grant cookies.
|
||||||
handler := csrfMiddleware("/rest", mux)
|
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.
|
// Wrap everything in basic auth, if user/password is set.
|
||||||
if len(cfg.User) > 0 {
|
if len(cfg.User) > 0 {
|
||||||
handler = basicAuthMiddleware(cfg.User, cfg.Password, handler)
|
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 {
|
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) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
h(m, w, r)
|
h(m, w, r)
|
||||||
|
|
Loading…
Reference in New Issue