6
6
import * as http from 'http' ;
7
7
import * as https from 'https' ;
8
8
import * as tls from 'tls' ;
9
+ import * as net from 'net' ;
9
10
10
11
import { IExtHostWorkspaceProvider } from 'vs/workbench/api/common/extHostWorkspace' ;
11
12
import { ExtHostConfigProvider } from 'vs/workbench/api/common/extHostConfiguration' ;
@@ -15,7 +16,7 @@ import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionS
15
16
import { URI } from 'vs/base/common/uri' ;
16
17
import { ILogService } from 'vs/platform/log/common/log' ;
17
18
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions' ;
18
- import { LogLevel , createHttpPatch , createProxyResolver , createTlsPatch , ProxySupportSetting } from '@vscode/proxy-agent' ;
19
+ import { LogLevel , createHttpPatch , createProxyResolver , createTlsPatch , ProxySupportSetting , ProxyAgentParams , createNetPatch } from '@vscode/proxy-agent' ;
19
20
20
21
export function connectProxyResolver (
21
22
extHostWorkspace : IExtHostWorkspaceProvider ,
@@ -27,7 +28,7 @@ export function connectProxyResolver(
27
28
) {
28
29
const useHostProxy = initData . environment . useHostProxy ;
29
30
const doUseHostProxy = typeof useHostProxy === 'boolean' ? useHostProxy : ! initData . remote . isRemote ;
30
- const resolveProxy = createProxyResolver ( {
31
+ const params : ProxyAgentParams = {
31
32
resolveProxy : url => extHostWorkspace . resolveProxy ( url ) ,
32
33
getHttpProxySetting : ( ) => configProvider . getConfiguration ( 'http' ) . get ( 'proxy' ) ,
33
34
log : ( level , message , ...args ) => {
@@ -50,13 +51,19 @@ export function connectProxyResolver(
50
51
// TODO @chrmarti Remove this from proxy agent
51
52
proxyResolveTelemetry : ( ) => { } ,
52
53
useHostProxy : doUseHostProxy ,
54
+ useSystemCertificatesV2 : certSettingV2 ( configProvider ) ,
55
+ addCertificates : [ ] ,
53
56
env : process . env ,
57
+ } ;
58
+ configProvider . onDidChangeConfiguration ( e => {
59
+ params . useSystemCertificatesV2 = certSettingV2 ( configProvider ) ;
54
60
} ) ;
55
- const lookup = createPatchedModules ( configProvider , resolveProxy ) ;
61
+ const resolveProxy = createProxyResolver ( params ) ;
62
+ const lookup = createPatchedModules ( params , configProvider , resolveProxy ) ;
56
63
return configureModuleLoading ( extensionService , lookup ) ;
57
64
}
58
65
59
- function createPatchedModules ( configProvider : ExtHostConfigProvider , resolveProxy : ReturnType < typeof createProxyResolver > ) {
66
+ function createPatchedModules ( params : ProxyAgentParams , configProvider : ExtHostConfigProvider , resolveProxy : ReturnType < typeof createProxyResolver > ) {
60
67
const proxySetting = {
61
68
config : configProvider . getConfiguration ( 'http' )
62
69
. get < ProxySupportSetting > ( 'proxySupport' ) || 'off'
@@ -66,12 +73,10 @@ function createPatchedModules(configProvider: ExtHostConfigProvider, resolveProx
66
73
. get < ProxySupportSetting > ( 'proxySupport' ) || 'off' ;
67
74
} ) ;
68
75
const certSetting = {
69
- config : ! ! configProvider . getConfiguration ( 'http' )
70
- . get < boolean > ( 'systemCertificates' )
76
+ config : certSettingV1 ( configProvider )
71
77
} ;
72
78
configProvider . onDidChangeConfiguration ( e => {
73
- certSetting . config = ! ! configProvider . getConfiguration ( 'http' )
74
- . get < boolean > ( 'systemCertificates' ) ;
79
+ certSetting . config = certSettingV1 ( configProvider ) ;
75
80
} ) ;
76
81
77
82
return {
@@ -89,17 +94,32 @@ function createPatchedModules(configProvider: ExtHostConfigProvider, resolveProx
89
94
onRequest : Object . assign ( { } , https , createHttpPatch ( https , resolveProxy , proxySetting , certSetting , true ) ) ,
90
95
default : Object . assign ( https , createHttpPatch ( https , resolveProxy , proxySetting , certSetting , false ) ) // run last
91
96
} as Record < string , typeof https > ,
92
- tls : Object . assign ( tls , createTlsPatch ( tls ) )
97
+ net : Object . assign ( net , createNetPatch ( params , net ) ) ,
98
+ tls : Object . assign ( tls , createTlsPatch ( params , tls ) )
93
99
} ;
94
100
}
95
101
102
+ function certSettingV1 ( configProvider : ExtHostConfigProvider ) {
103
+ const http = configProvider . getConfiguration ( 'http' ) ;
104
+ return ! http . get < boolean > ( 'experimental.systemCertificatesV2' ) && ! ! http . get < boolean > ( 'systemCertificates' ) ;
105
+ }
106
+
107
+ function certSettingV2 ( configProvider : ExtHostConfigProvider ) {
108
+ const http = configProvider . getConfiguration ( 'http' ) ;
109
+ return ! ! http . get < boolean > ( 'experimental.systemCertificatesV2' ) && ! ! http . get < boolean > ( 'systemCertificates' ) ;
110
+ }
111
+
96
112
const modulesCache = new Map < IExtensionDescription | undefined , { http ?: typeof http ; https ?: typeof https } > ( ) ;
97
113
function configureModuleLoading ( extensionService : ExtHostExtensionService , lookup : ReturnType < typeof createPatchedModules > ) : Promise < void > {
98
114
return extensionService . getExtensionPathIndex ( )
99
115
. then ( extensionPaths => {
100
116
const node_module = < any > globalThis . _VSCODE_NODE_MODULES . module ;
101
117
const original = node_module . _load ;
102
118
node_module . _load = function load ( request : string , parent : { filename : string } , isMain : boolean ) {
119
+ if ( request === 'net' ) {
120
+ return lookup . net ;
121
+ }
122
+
103
123
if ( request === 'tls' ) {
104
124
return lookup . tls ;
105
125
}
0 commit comments