@@ -9,14 +9,10 @@ import * as os from 'os';
99import * as child_process from 'child_process' ;
1010import * as vscode from 'vscode' ;
1111import * as Telemetry from './telemetry' ;
12- import HttpsProxyAgent = require( 'https-proxy-agent' ) ;
13- import * as url from 'url' ;
1412import { PlatformInformation } from './platform' ;
1513import { getOutputChannelLogger , showOutputChannel } from './logger' ;
1614import * as assert from 'assert' ;
17- import * as https from 'https' ;
1815import * as tmp from 'tmp' ;
19- import { ClientRequest , OutgoingHttpHeaders } from 'http' ;
2016import * as nls from 'vscode-nls' ;
2117import * as jsonc from 'comment-json' ;
2218import { TargetPopulation } from 'vscode-tas-client' ;
@@ -443,32 +439,6 @@ export function getDebugAdaptersPath(file: string): string {
443439 return path . resolve ( getExtensionFilePath ( "debugAdapters" ) , file ) ;
444440}
445441
446- export function getHttpsProxyAgent ( ) : HttpsProxyAgent | undefined {
447- let proxy : string | undefined = vscode . workspace . getConfiguration ( ) . get < string > ( 'http.proxy' ) ;
448- if ( ! proxy ) {
449- proxy = process . env . HTTPS_PROXY || process . env . https_proxy || process . env . HTTP_PROXY || process . env . http_proxy ;
450- if ( ! proxy ) {
451- return undefined ; // No proxy
452- }
453- }
454-
455- // Basic sanity checking on proxy url
456- const proxyUrl : any = url . parse ( proxy ) ;
457- if ( proxyUrl . protocol !== "https:" && proxyUrl . protocol !== "http:" ) {
458- return undefined ;
459- }
460-
461- const strictProxy : any = vscode . workspace . getConfiguration ( ) . get ( "http.proxyStrictSSL" , true ) ;
462- const proxyOptions : any = {
463- host : proxyUrl . hostname ,
464- port : parseInt ( proxyUrl . port , 10 ) ,
465- auth : proxyUrl . auth ,
466- rejectUnauthorized : strictProxy
467- } ;
468-
469- return new HttpsProxyAgent ( proxyOptions ) ;
470- }
471-
472442/** Test whether a file exists */
473443export function checkFileExists ( filePath : string ) : Promise < boolean > {
474444 return new Promise ( ( resolve , reject ) => {
@@ -899,79 +869,6 @@ export function createTempFileWithPostfix(postfix: string): Promise<tmp.FileResu
899869 } ) ;
900870}
901871
902- export function downloadFileToDestination ( urlStr : string , destinationPath : string , headers ?: OutgoingHttpHeaders ) : Promise < void > {
903- return new Promise < void > ( ( resolve , reject ) => {
904- const parsedUrl : url . Url = url . parse ( urlStr ) ;
905- const request : ClientRequest = https . request ( {
906- host : parsedUrl . host ,
907- path : parsedUrl . path ,
908- agent : getHttpsProxyAgent ( ) ,
909- rejectUnauthorized : vscode . workspace . getConfiguration ( ) . get ( 'http.proxyStrictSSL' , true ) ,
910- headers : headers
911- } , ( response ) => {
912- if ( response . statusCode === 301 || response . statusCode === 302 ) { // If redirected
913- // Download from new location
914- let redirectUrl : string ;
915- if ( typeof response . headers . location === 'string' ) {
916- redirectUrl = response . headers . location ;
917- } else {
918- if ( ! response . headers . location ) {
919- return reject ( new Error ( localize ( "invalid.download.location.received" , 'Invalid download location received' ) ) ) ;
920- }
921- redirectUrl = response . headers . location [ 0 ] ;
922- }
923- return resolve ( downloadFileToDestination ( redirectUrl , destinationPath , headers ) ) ;
924- }
925- if ( response . statusCode !== 200 ) { // If request is not successful
926- return reject ( ) ;
927- }
928- // Write file using downloaded data
929- const createdFile : fs . WriteStream = fs . createWriteStream ( destinationPath ) ;
930- createdFile . on ( 'finish' , ( ) => { resolve ( ) ; } ) ;
931- response . on ( 'error' , ( error ) => { reject ( error ) ; } ) ;
932- response . pipe ( createdFile ) ;
933- } ) ;
934- request . on ( 'error' , ( error ) => { reject ( error ) ; } ) ;
935- request . end ( ) ;
936- } ) ;
937- }
938-
939- export function downloadFileToStr ( urlStr : string , headers ?: OutgoingHttpHeaders ) : Promise < any > {
940- return new Promise < string > ( ( resolve , reject ) => {
941- const parsedUrl : url . Url = url . parse ( urlStr ) ;
942- const request : ClientRequest = https . request ( {
943- host : parsedUrl . host ,
944- path : parsedUrl . path ,
945- agent : getHttpsProxyAgent ( ) ,
946- rejectUnauthorized : vscode . workspace . getConfiguration ( ) . get ( 'http.proxyStrictSSL' , true ) ,
947- headers : headers
948- } , ( response ) => {
949- if ( response . statusCode === 301 || response . statusCode === 302 ) { // If redirected
950- // Download from new location
951- let redirectUrl : string ;
952- if ( typeof response . headers . location === 'string' ) {
953- redirectUrl = response . headers . location ;
954- } else {
955- if ( ! response . headers . location ) {
956- return reject ( new Error ( localize ( "invalid.download.location.received" , 'Invalid download location received' ) ) ) ;
957- }
958- redirectUrl = response . headers . location [ 0 ] ;
959- }
960- return resolve ( downloadFileToStr ( redirectUrl , headers ) ) ;
961- }
962- if ( response . statusCode !== 200 ) { // If request is not successful
963- return reject ( ) ;
964- }
965- let downloadedData : string = '' ;
966- response . on ( 'data' , ( data ) => { downloadedData += data ; } ) ;
967- response . on ( 'error' , ( error ) => { reject ( error ) ; } ) ;
968- response . on ( 'end' , ( ) => { resolve ( downloadedData ) ; } ) ;
969- } ) ;
970- request . on ( 'error' , ( error ) => { reject ( error ) ; } ) ;
971- request . end ( ) ;
972- } ) ;
973- }
974-
975872function resolveWindowsEnvironmentVariables ( str : string ) : string {
976873 return str . replace ( / % ( [ ^ % ] + ) % / g, ( withPercents , withoutPercents ) => {
977874 const found : string | undefined = process . env [ withoutPercents ] ;
0 commit comments