| 41 | } |
| 42 | |
| 43 | function startRequest(callback) { |
| 44 | const req = request(url, { |
| 45 | timeout, |
| 46 | agent, |
| 47 | lookup, |
| 48 | }, (res) => { |
| 49 | // Log the status code |
| 50 | if (!process.env.NO_LOG_REQUEST) { |
| 51 | console.log(`Status Code: ${res.statusCode}`); |
| 52 | console.log('Headers:', res.headers); |
| 53 | } |
| 54 | res.pipe(process.stdout); |
| 55 | |
| 56 | if (callback) { |
| 57 | res.on('end', callback); |
| 58 | } |
| 59 | }); |
| 60 | |
| 61 | req.on('error', (e) => { |
| 62 | console.error('Request Error', e); |
| 63 | }); |
| 64 | |
| 65 | req.on('timeout', () => { |
| 66 | console.error('Request timed out'); |
| 67 | req.destroy(); |
| 68 | }); |
| 69 | |
| 70 | req.end(); |
| 71 | } |
| 72 | |
| 73 | startRequest(() => { |
| 74 | if (process.env.CLEAR_GLOBAL_PROXY_AND_RETRY) { |