From d35171fce742e0029960ffe5297b98b539c22497 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Wed, 6 Nov 2024 09:44:16 +0100 Subject: [PATCH] Enable for remote (#228697) --- src/vs/platform/request/common/request.ts | 2 +- src/vs/workbench/api/node/proxyResolver.ts | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/vs/platform/request/common/request.ts b/src/vs/platform/request/common/request.ts index c7984e12e0a95..2c85ab8c043ae 100644 --- a/src/vs/platform/request/common/request.ts +++ b/src/vs/platform/request/common/request.ts @@ -213,7 +213,7 @@ function registerProxyConfigurations(scope: ConfigurationScope): void { 'http.fetchAdditionalSupport': { type: 'boolean', default: true, - description: localize('fetchAdditionalSupport', "Controls whether Node.js' fetch implementation should be extended with additional support."), + markdownDescription: localize('fetchAdditionalSupport', "Controls whether Node.js' fetch implementation should be extended with additional support. Currently proxy support ({0}) and system certificates ({1}) are added when the corresponding settings are enabled.", '`#http.proxySupport#`', '`#http.systemCertificates#`'), restricted: true } } diff --git a/src/vs/workbench/api/node/proxyResolver.ts b/src/vs/workbench/api/node/proxyResolver.ts index 2b676e4749709..33ccf16452705 100644 --- a/src/vs/workbench/api/node/proxyResolver.ts +++ b/src/vs/workbench/api/node/proxyResolver.ts @@ -109,18 +109,20 @@ const unsafeHeaders = [ ]; function patchGlobalFetch(configProvider: ExtHostConfigProvider, mainThreadTelemetry: MainThreadTelemetryShape, initData: IExtensionHostInitData, resolveProxyURL: (url: string) => Promise, lookupProxyAuthorization: LookupProxyAuthorization, loadAdditionalCertificates: () => Promise, disposables: DisposableStore) { - if (!initData.remote.isRemote && !(globalThis as any).__vscodeOriginalFetch) { + if (!(globalThis as any).__vscodeOriginalFetch) { const originalFetch = globalThis.fetch; (globalThis as any).__vscodeOriginalFetch = originalFetch; const patchedFetch = patchFetch(originalFetch, configProvider, resolveProxyURL, lookupProxyAuthorization, loadAdditionalCertificates); (globalThis as any).__vscodePatchedFetch = patchedFetch; - let useElectronFetch = configProvider.getConfiguration('http').get('electronFetch', useElectronFetchDefault); - disposables.add(configProvider.onDidChangeConfiguration(e => { - if (e.affectsConfiguration('http.electronFetch')) { - useElectronFetch = configProvider.getConfiguration('http').get('electronFetch', useElectronFetchDefault); - } - })); - const electron = require('electron'); + let useElectronFetch = false; + if (!initData.remote.isRemote) { + useElectronFetch = configProvider.getConfiguration('http').get('electronFetch', useElectronFetchDefault); + disposables.add(configProvider.onDidChangeConfiguration(e => { + if (e.affectsConfiguration('http.electronFetch')) { + useElectronFetch = configProvider.getConfiguration('http').get('electronFetch', useElectronFetchDefault); + } + })); + } // https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API globalThis.fetch = async function fetch(input: string | URL | Request, init?: RequestInit) { function getRequestProperty(name: keyof Request & keyof RequestInit) { @@ -160,6 +162,7 @@ function patchGlobalFetch(configProvider: ExtHostConfigProvider, mainThreadTelem } // Support for URL: https://github.com/electron/electron/issues/43712 const electronInput = input instanceof URL ? input.toString() : input; + const electron = require('electron'); const response = await electron.net.fetch(electronInput, init); monitorResponseProperties(mainThreadTelemetry, response, urlString); return response;