mirror of
https://github.com/anticensority/runet-censorship-bypass.git
synced 2024-11-23 18:03:44 +03:00
Make HEAD to Antizapret
This commit is contained in:
parent
c59ffda2e2
commit
8d749eb2ae
|
@ -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)
|
||||
);
|
||||
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@
|
|||
|
||||
};
|
||||
|
||||
const setPacScriptFromProviderAsync = function setPacScriptFromProviderAsync(
|
||||
const setPacScriptFromProviderAsync = async function setPacScriptFromProviderAsync(
|
||||
provider, lastModifiedStr = mandatory(), cb = throwIfError
|
||||
) {
|
||||
|
||||
|
@ -106,6 +106,29 @@
|
|||
'Getting PAC script from provider...', pacUrl,
|
||||
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) => {
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user