@@ -9,17 +9,28 @@ import * as zlib from "zlib";
9
9
import * as util from "util" ;
10
10
import * as path from "path" ;
11
11
import { log , assert } from "./util" ;
12
+ import * as url from "url" ;
13
+ import * as https from "https" ;
14
+ import { ProxySettings } from "./config" ;
12
15
13
16
const pipeline = util . promisify ( stream . pipeline ) ;
14
17
15
18
const GITHUB_API_ENDPOINT_URL = "https://api.github.com" ;
16
19
const OWNER = "rust-analyzer" ;
17
20
const REPO = "rust-analyzer" ;
18
21
22
+ function makeHttpAgent ( proxy : string | null | undefined , options ?: https . AgentOptions ) {
23
+ if ( proxy ) {
24
+ return new HttpsProxyAgent ( proxy , { ...options , ...url . parse ( proxy ) } ) ;
25
+ } else {
26
+ return new https . Agent ( options ) ;
27
+ }
28
+ }
29
+
19
30
export async function fetchRelease (
20
31
releaseTag : string ,
21
32
githubToken : string | null | undefined ,
22
- httpProxy : string | null | undefined ,
33
+ proxySettings : ProxySettings ,
23
34
) : Promise < GithubRelease > {
24
35
25
36
const apiEndpointPath = `/repos/${ OWNER } /${ REPO } /releases/tags/${ releaseTag } ` ;
@@ -34,12 +45,15 @@ export async function fetchRelease(
34
45
}
35
46
36
47
const response = await ( ( ) => {
37
- if ( httpProxy ) {
38
- log . debug ( `Fetching release metadata via proxy: ${ httpProxy } ` ) ;
39
- return fetch ( requestUrl , { headers : headers , agent : new HttpsProxyAgent ( httpProxy ) } ) ;
48
+ if ( proxySettings . proxy ) {
49
+ log . debug ( `Fetching release metadata via proxy: ${ proxySettings . proxy } ` ) ;
40
50
}
41
-
42
- return fetch ( requestUrl , { headers : headers } ) ;
51
+ const options : any = { } ;
52
+ if ( proxySettings . strictSSL ) {
53
+ options [ "rejectUnauthorized" ] = false ;
54
+ }
55
+ const agent = makeHttpAgent ( proxySettings . proxy , options ) ;
56
+ return fetch ( requestUrl , { headers : headers , agent : agent } ) ;
43
57
} ) ( ) ;
44
58
45
59
if ( ! response . ok ) {
@@ -83,7 +97,7 @@ interface DownloadOpts {
83
97
dest : vscode . Uri ;
84
98
mode ?: number ;
85
99
gunzip ?: boolean ;
86
- httpProxy ?: string ;
100
+ proxySettings : ProxySettings ;
87
101
}
88
102
89
103
export async function download ( opts : DownloadOpts ) {
@@ -103,7 +117,7 @@ export async function download(opts: DownloadOpts) {
103
117
} ,
104
118
async ( progress , _cancellationToken ) => {
105
119
let lastPercentage = 0 ;
106
- await downloadFile ( opts . url , tempFilePath , opts . mode , ! ! opts . gunzip , opts . httpProxy , ( readBytes , totalBytes ) => {
120
+ await downloadFile ( opts . url , tempFilePath , opts . mode , ! ! opts . gunzip , opts . proxySettings , ( readBytes , totalBytes ) => {
107
121
const newPercentage = Math . round ( ( readBytes / totalBytes ) * 100 ) ;
108
122
if ( newPercentage !== lastPercentage ) {
109
123
progress . report ( {
@@ -167,18 +181,21 @@ async function downloadFile(
167
181
destFilePath : vscode . Uri ,
168
182
mode : number | undefined ,
169
183
gunzip : boolean ,
170
- httpProxy : string | null | undefined ,
184
+ proxySettings : ProxySettings ,
171
185
onProgress : ( readBytes : number , totalBytes : number ) => void
172
186
) : Promise < void > {
173
187
const urlString = url . toString ( ) ;
174
188
175
189
const res = await ( ( ) => {
176
- if ( httpProxy ) {
177
- log . debug ( `Downloading ${ urlString } via proxy: ${ httpProxy } ` ) ;
178
- return fetch ( urlString , { agent : new HttpsProxyAgent ( httpProxy ) } ) ;
190
+ if ( proxySettings . proxy ) {
191
+ log . debug ( `Downloading ${ urlString } via proxy: ${ proxySettings . proxy } ` ) ;
179
192
}
180
-
181
- return fetch ( urlString ) ;
193
+ const options : any = { } ;
194
+ if ( proxySettings . strictSSL ) {
195
+ options [ "rejectUnauthorized" ] = false ;
196
+ }
197
+ const agent = makeHttpAgent ( proxySettings . proxy , options ) ;
198
+ return fetch ( urlString , { agent : agent } ) ;
182
199
} ) ( ) ;
183
200
184
201
if ( ! res . ok ) {
0 commit comments