Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ const del = require('del');
const gulp = require('gulp');
const tslint = require('gulp-tslint');
const vsce = require('vsce');
const omnisharpDownload = require('./out/omnisharpDownload');
//const omnisharpDownload = require('./out/omnisharpDownload');

gulp.task('omnisharp:clean', () => {
return del('.omnisharp');
});

gulp.task('omnisharp:fetch', ['omnisharp:clean'], () => {
return omnisharpDownload.downloadOmnisharp();
});
//TODO: decouple omnisharpDownload (specifically proxy.ts) from vscode
// gulp.task('omnisharp:fetch', ['omnisharp:clean'], () => {
// return omnisharpDownload.downloadOmnisharp();
// });

const allTypeScript = [
'src/**/*.ts',
Expand Down Expand Up @@ -45,7 +46,7 @@ gulp.task('tslint', () => {
}))
});

gulp.task('omnisharp', ['omnisharp:fetch']);
// gulp.task('omnisharp', ['omnisharp:fetch']);

gulp.task('package', () => {
vsce(['', '', 'package']);
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
"decompress": "^3.0.0",
"del": "^2.0.2",
"fs-extra-promise": "^0.3.1",
"http-proxy-agent": "^1.0.0",
"https-proxy-agent": "^1.0.0",
"open": "*",
"semver": "*",
"vscode-debugprotocol": "^1.6.1",
"vscode-extension-telemetry": "0.0.4",
"tmp": "0.0.28",
"open": "*"
"vscode-debugprotocol": "^1.6.1",
"vscode-extension-telemetry": "0.0.4"
},
"devDependencies": {
"gulp": "^3.9.1",
Expand Down Expand Up @@ -364,4 +366,4 @@
}
]
}
}
}
7 changes: 6 additions & 1 deletion src/omnisharpDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as stream from 'stream';
import * as tmp from 'tmp';
import {parse} from 'url';
import {SupportedPlatform, getSupportedPlatform} from './utils';
import {getProxyAgent} from './proxy';

const Decompress = require('decompress');

Expand Down Expand Up @@ -48,10 +49,14 @@ function getOmnisharpAssetName(): string {

function download(urlString: string): Promise<stream.Readable> {
let url = parse(urlString);

const agent = getProxyAgent(url);

let options: https.RequestOptions = {
host: url.host,
path: url.path,
}
agent: agent
};

return new Promise<stream.Readable>((resolve, reject) => {
return https.get(options, res => {
Expand Down
46 changes: 46 additions & 0 deletions src/proxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh... I wish we didn't have to copy and paste this from VS Code and could just leverage their that's already running. But, 👍

* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

'use strict';

import { Url, parse as parseUrl } from 'url';
import HttpProxyAgent = require('http-proxy-agent');
import HttpsProxyAgent = require('https-proxy-agent');
import {workspace} from 'vscode';

function getSystemProxyURL(requestURL: Url): string {
if (requestURL.protocol === 'http:') {
return process.env.HTTP_PROXY || process.env.http_proxy || null;
} else if (requestURL.protocol === 'https:') {
return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy || null;
}

return null;
}

export function getProxyAgent(requestURL: Url): any {
const vsConfigProxyUrl = workspace.getConfiguration().get<string>('http.proxy');
const proxyURL = vsConfigProxyUrl || getSystemProxyURL(requestURL);

if (!proxyURL) {
return null;
}

const proxyEndpoint = parseUrl(proxyURL);

if (!/^https?:$/.test(proxyEndpoint.protocol)) {
return null;
}

const strictSSL = workspace.getConfiguration().get('http.proxyStrictSSL', true);
const opts = {
host: proxyEndpoint.hostname,
port: Number(proxyEndpoint.port),
auth: proxyEndpoint.auth,
rejectUnauthorized: strictSSL
};

return requestURL.protocol === 'http:' ? new HttpProxyAgent(opts) : new HttpsProxyAgent(opts);
}
20 changes: 20 additions & 0 deletions src/typings/http-proxy-agent/http-proxy-agent.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

declare module 'http-proxy-agent' {

interface IHttpProxyAgentOptions {
host: string;
port: number;
auth?: string;
}

class HttpProxyAgent {
constructor(proxy: string);
constructor(opts: IHttpProxyAgentOptions);
}

export = HttpProxyAgent;
}
24 changes: 24 additions & 0 deletions src/typings/https-proxy-agent/https-proxy-agent.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

declare module 'https-proxy-agent' {

import * as tls from 'tls';

interface IHttpsProxyAgentOptions extends tls.ConnectionOptions {
host: string;
port: number;
auth?: string;
secureProxy?: boolean;
secureEndpoint?: boolean;
}

class HttpsProxyAgent {
constructor(proxy: string);
constructor(opts: IHttpsProxyAgentOptions);
}

export = HttpsProxyAgent;
}