(url, options = {})
| 142 | } |
| 143 | |
| 144 | async function httpGet(url, options = {}) { |
| 145 | const reqOptions = await buildRequestOptions(url, options) |
| 146 | |
| 147 | return new Promise((resolve, reject) => { |
| 148 | const req = httpsModule.get(reqOptions, (res) => { |
| 149 | if (res.statusCode === 301 || res.statusCode === 302) { |
| 150 | res.resume() |
| 151 | httpGet(new URL(res.headers.location, url).href, options) |
| 152 | .then(resolve) |
| 153 | .catch(reject) |
| 154 | return |
| 155 | } |
| 156 | |
| 157 | resolve(res) |
| 158 | }) |
| 159 | |
| 160 | req.on('error', reject) |
| 161 | req.setTimeout(options.timeout || requestTimeout, () => { |
| 162 | req.destroy() |
| 163 | reject(new Error('Request timeout.')) |
| 164 | }) |
| 165 | }) |
| 166 | } |
| 167 | |
| 168 | return { |
| 169 | getProxyUrl, |
no test coverage detected