Merge pull request #2079 from snnd/bugfix_reloads

fix(core): prevent endless reload on cache requests
This commit is contained in:
Audrius Butkevicius 2015-07-21 23:01:15 +01:00
commit 42dc51784e

View File

@ -15,27 +15,40 @@ var syncthing = angular.module('syncthing', [
]); ]);
var urlbase = 'rest'; var urlbase = 'rest';
syncthing.config(function ($httpProvider, $translateProvider, LocaleServiceProvider) {
$httpProvider.interceptors.push(function xHeadersResponseInterceptor() {
var guiVersion = null; var guiVersion = null;
var deviceId = null; var deviceId = null;
syncthing.config(function ($httpProvider, $translateProvider, LocaleServiceProvider) {
$httpProvider.interceptors.push(function () {
return { return {
response: function (response) { response: function onResponse(response) {
var responseVersion = response.headers()['x-syncthing-version']; 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) { 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); 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;
} }
}; };