UNPKG

1.51 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
3// Node module: @loopback/testlab
4// This file is licensed under the MIT License.
5// License text available at https://opensource.org/licenses/MIT
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.httpsGetAsync = exports.httpGetAsync = void 0;
8const tslib_1 = require("tslib");
9const http_1 = tslib_1.__importDefault(require("http"));
10const https_1 = tslib_1.__importDefault(require("https"));
11const url_1 = tslib_1.__importDefault(require("url"));
12/**
13 * Async wrapper for making HTTP GET requests
14 * @param urlString
15 */
16function httpGetAsync(urlString, agent) {
17 return new Promise((resolve, reject) => {
18 const urlOptions = url_1.default.parse(urlString);
19 const options = { agent, ...urlOptions };
20 http_1.default.get(options, resolve).on('error', reject);
21 });
22}
23exports.httpGetAsync = httpGetAsync;
24/**
25 * Async wrapper for making HTTPS GET requests
26 * @param urlString
27 */
28function httpsGetAsync(urlString, agent) {
29 agent =
30 agent !== null && agent !== void 0 ? agent : new https_1.default.Agent({
31 rejectUnauthorized: false,
32 });
33 const urlOptions = url_1.default.parse(urlString);
34 const options = { agent, ...urlOptions };
35 return new Promise((resolve, reject) => {
36 https_1.default.get(options, resolve).on('error', reject);
37 });
38}
39exports.httpsGetAsync = httpsGetAsync;
40//# sourceMappingURL=request.js.map
\No newline at end of file