* @param {string} url * @param {object} options * @param {string=} data * @return {!Promise<{res: *, body: string}>}
(url, options, data)
| 89 | * @return {!Promise<{res: *, body: string}>} |
| 90 | */ |
| 91 | function httpsRequest(url, options, data) { |
| 92 | return new Promise((resolve, reject) => { |
| 93 | const req = https.request(url, options, (res) => { |
| 94 | const chunks = []; |
| 95 | res.on('data', (chunk) => { |
| 96 | chunks.push(Buffer.from(chunk)); |
| 97 | }); |
| 98 | res.on('close', () => { |
| 99 | const body = Buffer.concat(chunks).toString('utf-8'); |
| 100 | resolve({res, body}); |
| 101 | }); |
| 102 | }); |
| 103 | req.on('error', (error) => { |
| 104 | reject(error); |
| 105 | }); |
| 106 | if (data) { |
| 107 | req.write(data); |
| 108 | } |
| 109 | req.end(); |
| 110 | }); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @param {string} token |