fix(core): prevent endless reload on cache requests

This commit is contained in:
Dennis Wilson 2015-07-21 22:35:51 +02:00
parent 895d56ed04
commit dfcc166918

View File

@ -22,20 +22,26 @@ syncthing.config(function ($httpProvider, $translateProvider, LocaleServiceProvi
$httpProvider.interceptors.push(function () { $httpProvider.interceptors.push(function () {
return { return {
response: function (response) { response: function (response) {
var responseVersion = response.headers()['x-syncthing-version']; var headers = response.headers();
// angular template cache sends no headers
if(Object.keys(headers).length > 0) {
var responseVersion = headers['x-syncthing-version'];
if (!guiVersion) { if (!guiVersion) {
guiVersion = responseVersion; guiVersion = responseVersion;
} else if (guiVersion != responseVersion) { } else if (guiVersion != responseVersion) {
document.location.reload(true); document.location.reload(true);
} }
if (!deviceId) { if (!deviceId) {
deviceId = response.headers()['x-syncthing-id']; deviceId = headers['x-syncthing-id'];
if (deviceId) { if (deviceId) {
var deviceIdShort = deviceId.substring(0, 5); var deviceIdShort = deviceId.substring(0, 5);
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token-' + deviceIdShort; $httpProvider.defaults.xsrfHeaderName = 'X-CSRF-Token-' + deviceIdShort;
$httpProvider.defaults.xsrfCookieName = 'CSRF-Token-' + deviceIdShort; $httpProvider.defaults.xsrfCookieName = 'CSRF-Token-' + deviceIdShort;
} }
} }
}
return response; return response;
} }
}; };