(url, needBinary, httpOptions)
| 418 | } |
| 419 | |
| 420 | function fetchHttp (url, needBinary, httpOptions) { |
| 421 | return new Promise((accept, reject) => { |
| 422 | const parsed = new URL(url); |
| 423 | const protocol = (parsed.protocol === 'https:' ? https : http); |
| 424 | try { |
| 425 | protocol.get(Object.assign({ |
| 426 | host: parsed.host, |
| 427 | path: parsed.pathname + parsed.search |
| 428 | }, httpOptions || {}), (res) => { |
| 429 | toUtf8(res, (contentType, content) => { |
| 430 | accept({statusCode: res.statusCode, statusMessage: res.statusMessage, content, contentType}); |
| 431 | }, needBinary); |
| 432 | }).on('error', reject); |
| 433 | } catch (e) { |
| 434 | console.error('Cannot fetch', url, e); |
| 435 | reject(e); |
| 436 | } |
| 437 | }); |
| 438 | } |
| 439 | |
| 440 | function uploadHttpFile (url, filePath, httpHeaders, httpOptions, needBinary) { |
| 441 | return new Promise((accept, reject) => { |
no test coverage detected