1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import {IncomingMessage} from 'http';
|
7 | import * as http from 'http';
|
8 | import * as https from 'https';
|
9 | import * as url from 'url';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export function httpGetAsync(urlString: string): Promise<IncomingMessage> {
|
16 | return new Promise((resolve, reject) => {
|
17 | http.get(urlString, resolve).on('error', reject);
|
18 | });
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | export function httpsGetAsync(urlString: string): Promise<IncomingMessage> {
|
26 | const agent = new https.Agent({
|
27 | rejectUnauthorized: false,
|
28 | });
|
29 |
|
30 | const urlOptions = url.parse(urlString);
|
31 | const options = {agent, ...urlOptions};
|
32 |
|
33 | return new Promise((resolve, reject) => {
|
34 | https.get(options, resolve).on('error', reject);
|
35 | });
|
36 | }
|