Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #170 from microsoft/pine/154
Browse files Browse the repository at this point in the history
Fix #154
  • Loading branch information
octref authored Apr 23, 2020
2 parents 216c61a + 71ff0ef commit faa0254
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 387 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ The `vscode` NPM module provides VS Code extension authors tools to write extens

For more information around extension authoring for VS Code, please see http://code.visualstudio.com/docs/extensions/overview

# License
## Changes

**1.1.37** | 2020-04-22

- Remove `request` and `url-parse` dependencies. [#154](https://github.com/microsoft/vscode-extension-vscode/issues/154).

## License

[MIT](LICENSE)
2 changes: 1 addition & 1 deletion bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function getURLMatchingEngine(engine, callback) {
});
}

shared.getContents('https://vscode-update.azurewebsites.net/api/releases/stable', null, { "X-API-Version": "2" }, function (error, tagsRaw) {
shared.getContents('https://update.code.visualstudio.com/api/releases/stable', null, { "X-API-Version": "2" }, function (error, tagsRaw) {
if (error) {
exitWithError(error);
}
Expand Down
58 changes: 36 additions & 22 deletions lib/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,54 @@
*--------------------------------------------------------*/
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
var request = require('request');
var URL = require('url-parse');
var url_1 = require("url");
var https = require("https");
var HttpsProxyAgent = require('https-proxy-agent');
var HttpProxyAgent = require('http-proxy-agent');
var PROXY_AGENT = undefined;
var HTTPS_PROXY_AGENT = undefined;
if (process.env.npm_config_proxy) {
PROXY_AGENT = new HttpProxyAgent(process.env.npm_config_proxy);
HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_proxy);
}
if (process.env.npm_config_https_proxy) {
HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_https_proxy);
}
function getContents(url, token, headers, callback) {
request.get(toRequestOptions(url, token, headers), function (error, response, body) {
if (!error && response && response.statusCode >= 400) {
error = new Error('Request returned status code: ' + response.statusCode + '\nDetails: ' + response.body);
var options = toRequestOptions(url, token, headers);
https.get(options, function (res) {
if (res && res.statusCode >= 400) {
callback(new Error('Request returned status code: ' + res.statusCode));
}
callback(error, body);
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
callback(null, data);
});
}).on('error', function (e) {
callback(e);
});
}
exports.getContents = getContents;
function toRequestOptions(url, token, headers) {
headers = headers || {
'user-agent': 'nodejs'
};
if (headers === void 0) { headers = { 'user-agent': 'nodejs' }; }
var options = url_1.parse(url);
if (PROXY_AGENT && options.protocol.startsWith('http:')) {
options.agent = PROXY_AGENT;
}
if (HTTPS_PROXY_AGENT && options.protocol.startsWith('https:')) {
options.agent = HTTPS_PROXY_AGENT;
}
if (token) {
headers['Authorization'] = 'token ' + token;
}
var parsedUrl = new URL(url);
var options = {
url: url,
headers: headers
};
options.headers = headers;
// We need to test the absence of true here because there is an npm bug that will not set boolean
// env variables if they are set to false.
if (process.env.npm_config_strict_ssl !== 'true') {
options.strictSSL = false;
}
if (process.env.npm_config_proxy && parsedUrl.protocol === 'http:') {
options.proxy = process.env.npm_config_proxy;
}
else if (process.env.npm_config_https_proxy && parsedUrl.protocol === 'https:') {
options.proxy = process.env.npm_config_https_proxy;
options.rejectUnauthorized = false;
}
return options;
}
exports.toRequestOptions = toRequestOptions;
67 changes: 43 additions & 24 deletions lib/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,64 @@

'use strict';

var request = require('request');
var URL = require('url-parse');
import { parse as parseUrl } from 'url';
import * as https from 'https';

export function getContents(url, token, headers, callback) {
request.get(toRequestOptions(url, token, headers), function (error, response, body) {
if (!error && response && response.statusCode >= 400) {
error = new Error('Request returned status code: ' + response.statusCode + '\nDetails: ' + response.body);
const HttpsProxyAgent = require('https-proxy-agent');
const HttpProxyAgent = require('http-proxy-agent');

let PROXY_AGENT = undefined;
let HTTPS_PROXY_AGENT = undefined;

if (process.env.npm_config_proxy) {
PROXY_AGENT = new HttpProxyAgent(process.env.npm_config_proxy);
HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_proxy);
}
if (process.env.npm_config_https_proxy) {
HTTPS_PROXY_AGENT = new HttpsProxyAgent(process.env.npm_config_https_proxy);
}

export function getContents(url: string, token?: string, headers?: any, callback?: (err: Error, body?: any) => void) {
const options = toRequestOptions(url, token, headers);

https.get(options, res => {
if (res && res.statusCode >= 400) {
callback(new Error('Request returned status code: ' + res.statusCode));
}

callback(error, body);
let data = '';

res.on('data', chunk => {
data += chunk;
});

res.on('end', () => {
callback(null, data);
});
}).on('error', e => {
callback(e);
});
}

export function toRequestOptions(url, token, headers) {
headers = headers || {
'user-agent': 'nodejs'
};
function toRequestOptions(url: string, token: string | null, headers = { 'user-agent': 'nodejs' }): https.RequestOptions {
const options: https.RequestOptions = parseUrl(url);
if (PROXY_AGENT && options.protocol.startsWith('http:')) {
options.agent = PROXY_AGENT;
}
if (HTTPS_PROXY_AGENT && options.protocol.startsWith('https:')) {
options.agent = HTTPS_PROXY_AGENT;
}

if (token) {
headers['Authorization'] = 'token ' + token;
}

let parsedUrl = new URL(url);

var options: any = {
url: url,
headers: headers
};
options.headers = headers;

// We need to test the absence of true here because there is an npm bug that will not set boolean
// env variables if they are set to false.
if (process.env.npm_config_strict_ssl !== 'true') {
options.strictSSL = false;
}

if (process.env.npm_config_proxy && parsedUrl.protocol === 'http:') {
options.proxy = process.env.npm_config_proxy;
} else if (process.env.npm_config_https_proxy && parsedUrl.protocol === 'https:') {
options.proxy = process.env.npm_config_https_proxy;
options.rejectUnauthorized = false;
}

return options;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
},
"dependencies": {
"glob": "^7.1.2",
"http-proxy-agent": "^4.0.1",
"https-proxy-agent": "^5.0.0",
"mocha": "^5.2.0",
"request": "^2.88.0",
"semver": "^5.4.1",
"source-map-support": "^0.5.0",
"url-parse": "^1.4.4",
"vscode-test": "^0.4.1"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit faa0254

Please sign in to comment.