diff --git a/gui/scripts/syncthing/app.js b/gui/scripts/syncthing/app.js index b85da427..9d260efc 100644 --- a/gui/scripts/syncthing/app.js +++ b/gui/scripts/syncthing/app.js @@ -15,27 +15,40 @@ var syncthing = angular.module('syncthing', [ ]); var urlbase = 'rest'; -var guiVersion = null; -var deviceId = null; syncthing.config(function ($httpProvider, $translateProvider, LocaleServiceProvider) { - $httpProvider.interceptors.push(function () { + $httpProvider.interceptors.push(function xHeadersResponseInterceptor() { + var guiVersion = null; + var deviceId = null; + return { - response: function (response) { - var responseVersion = response.headers()['x-syncthing-version']; + response: function onResponse(response) { + var headers = response.headers(); + var responseVersion; + var deviceIdShort; + + // angular template cache sends no headers + if(Object.keys(headers).length === 0) { + return response; + } + + responseVersion = headers['x-syncthing-version']; + if (!guiVersion) { guiVersion = responseVersion; } else if (guiVersion != responseVersion) { document.location.reload(true); } + if (!deviceId) { - deviceId = response.headers()['x-syncthing-id']; + deviceId = headers['x-syncthing-id']; if (deviceId) { - var deviceIdShort = deviceId.substring(0, 5); + deviceIdShort = deviceId.substring(0, 5); $httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token-' + deviceIdShort; $httpProvider.defaults.xsrfCookieName = 'CSRF-Token-' + deviceIdShort; } } + return response; } };