Make HEAD to Antizapret

This commit is contained in:
Ilya Ig. Petrov 2018-01-27 17:21:28 +05:00
parent c59ffda2e2
commit 8d749eb2ae
2 changed files with 49 additions and 1 deletions

View File

@ -78,6 +78,31 @@
}, },
head(url, cb = mandatory()) {
const start = Date.now();
fetch(url, {cache: 'no-store', method: 'HEAD'}).then(
(res) => {
const status = res.status;
if ( !( status >= 200 && status < 300 || status === 304 ) ) {
return cb(
errorsLib.clarify(
res,
'Получен ответ с неудачным HTTP-кодом ' + status + '.'
)
);
}
console.log('HEADed with success:', url, Date.now() - start);
cb();
},
errorsLib.clarifyThen(checkCon, cb)
);
},
}; };
} }

View File

@ -97,7 +97,7 @@
}; };
const setPacScriptFromProviderAsync = function setPacScriptFromProviderAsync( const setPacScriptFromProviderAsync = async function setPacScriptFromProviderAsync(
provider, lastModifiedStr = mandatory(), cb = throwIfError provider, lastModifiedStr = mandatory(), cb = throwIfError
) { ) {
@ -106,6 +106,29 @@
'Getting PAC script from provider...', pacUrl, 'Getting PAC script from provider...', pacUrl,
cb cb
); );
// TODO: dirty hack (labels should be UI related only)
if (provider.label === 'Антицензорити') {
const azUrl = window.apis.antiCensorRu.pacProviders['Антизапрет'].pacUrls[0];
console.log('HEADing antizapret...');
let headError = null;
const numberOfTries = 2;
let i = 0;
while (i++ < numberOfTries) {
await new Promise((resolve) =>
httpLib.head(azUrl, (err) => {
headError = err;
if (!headError) {
i = numberOfTries;
}
resolve();
})
);
}
if (headError) {
clarifyThen(\`\${azUrl} недоступен!\`, cb)(headError);
return;
}
}
httpLib.ifModifiedSince(pacUrl, lastModifiedStr, (err, newLastModifiedStr) => { httpLib.ifModifiedSince(pacUrl, lastModifiedStr, (err, newLastModifiedStr) => {