Simple GET helper that returns { status, body }.
(url: string)
| 14 | |
| 15 | /** Simple GET helper that returns { status, body }. */ |
| 16 | async function httpGet(url: string): Promise<{ status: number; body: string }> { |
| 17 | return new Promise((resolve, reject) => { |
| 18 | http |
| 19 | .get(url, (res) => { |
| 20 | let body = ""; |
| 21 | res.on("data", (chunk: Buffer) => { |
| 22 | body += chunk.toString(); |
| 23 | }); |
| 24 | res.on("end", () => resolve({ status: res.statusCode ?? 0, body })); |
| 25 | }) |
| 26 | .on("error", reject); |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | // --------------------------------------------------------------------------- |
| 31 | // Tests |
no test coverage detected