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