From 3a1ce3d5103f4a4a9af303a42373bbc9b376cfbd Mon Sep 17 00:00:00 2001 From: Ricbet Date: Tue, 10 Dec 2019 16:30:45 +0800 Subject: [PATCH 1/2] fix --- lib/download.js | 12 +++++++++++- package.json | 3 +++ yarn.lock | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 yarn.lock diff --git a/lib/download.js b/lib/download.js index ecc23c3..8b573f3 100644 --- a/lib/download.js +++ b/lib/download.js @@ -9,6 +9,10 @@ const util = require('util'); const url = require('url'); const child_process = require('child_process'); +var HttpsProxyAgent = require('https-proxy-agent') +var proxy = process.env.http_proxy || process.env.https_proxy; +var agent = new HttpsProxyAgent(proxy); + const packageVersion = require('../package.json').version; const tmpDir = path.join(os.tmpdir(), `vscode-ripgrep-cache-${packageVersion}`); @@ -101,6 +105,11 @@ function get(_url, opts) { ...url.parse(_url), ...opts }; + + if (process.env.https_proxy || process.env.http_proxy) { + opts.agent = agent; + } + https.get(opts, response => { if (response.statusCode !== 200) { reject(new Error('Request failed: ' + response.statusCode)); @@ -122,7 +131,8 @@ function get(_url, opts) { } function getApiUrl(repo, tag) { - return `https://api.github.com/repos/${repo}/releases/tags/${tag}`; + // return `https://api.github.com/repos/${repo}/releases/tags/${tag}`; + return `https://cs-archive-1257242599.cos.ap-shanghai.myqcloud.com/vscode-ripgrep/v11.0.1-2`; } /** diff --git a/package.json b/package.json index 61c9584..9192b27 100644 --- a/package.json +++ b/package.json @@ -15,5 +15,8 @@ "license": "MIT", "devDependencies": { "@types/node": "^10.12.0" + }, + "dependencies": { + "https-proxy-agent": "^3.0.1" } } diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..58b1b67 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,47 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/node@^10.12.0": + version "10.17.8" + resolved "https://registry.yarnpkg.com/@types/node/-/node-10.17.8.tgz#07c0819207b4bb46e5a509fe25f3232e76fa6683" + integrity sha512-FeTtEwXbQa187ABpeEQoO7pq3dHgE85FmAUExx2sKO6U1/MYrLTYv+BIMcgVbQ66WjI4w+Ni+5HJtY+gHgWnPg== + +agent-base@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee" + integrity sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg== + dependencies: + es6-promisify "^5.0.0" + +debug@^3.1.0: + version "3.2.6" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" + integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== + dependencies: + ms "^2.1.1" + +es6-promise@^4.0.3: + version "4.2.8" + resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a" + integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w== + +es6-promisify@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203" + integrity sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM= + dependencies: + es6-promise "^4.0.3" + +https-proxy-agent@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-3.0.1.tgz#b8c286433e87602311b01c8ea34413d856a4af81" + integrity sha512-+ML2Rbh6DAuee7d07tYGEKOEi2voWPUGan+ExdPbPW6Z3svq+JCqr0v8WmKPOkz1vOVykPCBSuobe7G8GJUtVg== + dependencies: + agent-base "^4.3.0" + debug "^3.1.0" + +ms@^2.1.1: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== From 4c516b53057d55bdad06012c808a558ee322ddf8 Mon Sep 17 00:00:00 2001 From: Ricbet Date: Tue, 10 Dec 2019 16:55:23 +0800 Subject: [PATCH 2/2] fix --- lib/download.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/download.js b/lib/download.js index 8b573f3..229541f 100644 --- a/lib/download.js +++ b/lib/download.js @@ -75,6 +75,13 @@ function download(_url, dest, opts) { ...url.parse(_url), ...opts }; + + if (process.env.https_proxy || process.env.http_proxy) { + mergedOpts.agent = agent; + } + + console.log("mergedOpts: "+JSON.stringify(mergedOpts)); + https.get(mergedOpts, response => { console.log('statusCode: ' + response.statusCode); if (response.statusCode === 302) {