File size: 584 Bytes
ff883f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const https = require('https')

module.exports = (url, filter = false) => {
  return new Promise((resolve, reject) => {
    const options = new URL(url)
    options.headers = {
      'User-Agent': 'curl/8.4.0'
    }

    https.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))
      })
    })
  })
}