UNPKG

999 BPlain TextView Raw
1// Copyright IBM Corp. 2018. All Rights Reserved.
2// Node module: @loopback/testlab
3// This file is licensed under the MIT License.
4// License text available at https://opensource.org/licenses/MIT
5
6import {IncomingMessage} from 'http';
7import * as http from 'http';
8import * as https from 'https';
9import * as url from 'url';
10
11/**
12 * Async wrapper for making HTTP GET requests
13 * @param urlString
14 */
15export 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 * Async wrapper for making HTTPS GET requests
23 * @param urlString
24 */
25export 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}