microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev/v-peq/add-expo-packager-command-tests

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/common/node/request.ts

29lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import http = require("http");
5import https = require("https");
6
7export class Request {
8 public static request(url: string, expectStatusOK = false, isHttps = false): Promise<string> {
9 return new Promise((resolve, reject) => {
10 // CodeQL [SM04580] extension send all requests to 'localhost:port' which are built by local application
11 const req = (isHttps ? https : http).get(url, res => {
12 let responseString = "";
13 res.on("data", (data: Buffer) => {
14 responseString += data.toString();
15 });
16 res.on("end", () => {
17 if (expectStatusOK && res.statusCode !== 200) {
18 reject(new Error(responseString));
19 } else {
20 resolve(responseString);
21 }
22 });
23 });
24 req.on("error", (err: Error) => {
25 reject(err);
26 });
27 });
28 }
29}
30