MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / initializeNetworkProxy

Function initializeNetworkProxy

src/utils/networkProxy.ts:115–182  ·  view source on GitHub ↗
(
	context: vscode.ExtensionContext,
	channel?: vscode.OutputChannel,
)

Source from the content-addressed store, hash-verified

113 * @param channel Optional output channel for logging
114 */
115export async function initializeNetworkProxy(
116 context: vscode.ExtensionContext,
117 channel?: vscode.OutputChannel,
118): Promise<void> {
119 extensionContext = context
120
121 // extensionMode is immutable for the process lifetime - exit early if not in debug mode.
122 // This avoids any overhead (listeners, logging, etc.) in production.
123 const isDebugMode = context.extensionMode === vscode.ExtensionMode.Development
124 if (!isDebugMode) {
125 return
126 }
127
128 outputChannel = channel ?? null
129 loggingEnabled = true
130 consoleLoggingEnabled = !outputChannel
131
132 const config = getProxyConfig()
133
134 log(`Initializing network proxy module...`)
135 log(
136 `Proxy config: enabled=${config.enabled}, serverUrl=${redactProxyUrl(config.serverUrl)}, tlsInsecure=${config.tlsInsecure}`,
137 )
138
139 // Listen for configuration changes to allow toggling proxy during a debug session.
140 // Guard for test environments where onDidChangeConfiguration may not be mocked.
141 if (typeof vscode.workspace.onDidChangeConfiguration === "function") {
142 context.subscriptions.push(
143 vscode.workspace.onDidChangeConfiguration((e) => {
144 if (
145 e.affectsConfiguration(`${Package.name}.debugProxy.enabled`) ||
146 e.affectsConfiguration(`${Package.name}.debugProxy.serverUrl`) ||
147 e.affectsConfiguration(`${Package.name}.debugProxy.tlsInsecure`)
148 ) {
149 const newConfig = getProxyConfig()
150
151 if (newConfig.enabled) {
152 applyTlsVerificationOverride(newConfig)
153 configureGlobalProxy(newConfig)
154 configureUndiciProxy(newConfig)
155 } else {
156 // Proxy disabled - but we can't easily un-bootstrap global-agent or reset undici dispatcher safely.
157 // We *can* restore any global fetch patch immediately.
158 restoreGlobalFetchPatch()
159 restoreTlsVerificationOverride()
160 log("Debug proxy disabled. Restart VS Code to fully disable proxy routing.")
161 }
162 }
163 }),
164 )
165 }
166
167 // Ensure we restore any overrides when the extension unloads.
168 context.subscriptions.push({
169 dispose: () => {
170 restoreGlobalFetchPatch()
171 restoreTlsVerificationOverride()
172 },

Callers 2

activateFunction · 0.90

Calls 10

getProxyConfigFunction · 0.85
redactProxyUrlFunction · 0.85
configureGlobalProxyFunction · 0.85
configureUndiciProxyFunction · 0.85
restoreGlobalFetchPatchFunction · 0.85
affectsConfigurationMethod · 0.80
logFunction · 0.70

Tested by

no test coverage detected