File size: 775 Bytes
c015809 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import https from 'https';
import http from 'http';
export default (url, filter = false) => {
return new Promise((resolve, reject) => {
const options = new URL(url);
options.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0',
};
const protocol = url.startsWith('https:') ? https : http;
protocol.get(options, res => {
if (filter && filter(res.headers)) {
resolve(Buffer.concat([]));
}
const chunks = [];
res.on('error', err => {
reject(err);
});
res.on('data', chunk => {
chunks.push(chunk);
});
res.on('end', () => {
resolve(Buffer.concat(chunks));
});
}).on('error', err => {
reject(err);
});
});
};
|