Skip to content

Add http proxy support to extension host #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"native-is-elevated": "0.4.3",
"native-watchdog": "1.3.0",
"node-pty": "0.11.0-beta11",
"proxy-agent": "^5.0.0",
"spdlog": "^0.13.0",
"tas-client-umd": "0.1.4",
"v8-inspect-profiler": "^0.0.22",
Expand Down
19 changes: 19 additions & 0 deletions src/vs/platform/request/node/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,22 @@ export async function getProxyAgent(rawRequestURL: string, env: typeof process.e
? new (await import('http-proxy-agent'))(opts as any as Url)
: new (await import('https-proxy-agent'))(opts);
}

/**
* Patch the node http and https modules to route all requests through the agent
* we get from the proxy-agent package if a proxy is set in the environment.
*
* @author coder
*/
export async function monkeyPatchHttpAgent(): Promise<void> {
if (process.env.http_proxy || process.env.https_proxy || process.env.HTTP_PROXY || process.env.HTTPS_PROXY) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add no_proxy as an option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, no_proxy is for specifying exceptions; the proxy agent module will check no_proxy when making a request to see whether it should send through the proxy or not.

If http_proxy and friends are not set then no_proxy has no effect.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I see now. Thanks for clarifying!

const http = require('http')
const https = require('https')

// If we do not pass in a proxy URL, proxy-agent will get the URL from the
// environment. See https://www.npmjs.com/package/proxy-from-env.
const pa = new (await import('proxy-agent'))();
http.globalAgent = pa;
https.globalAgent = pa;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { realpath } from 'vs/base/node/extpath';
import { IHostUtils } from 'vs/workbench/api/common/extHostExtensionService';
import { ProcessTimeRunOnceScheduler } from 'vs/base/common/async';
import { boolean } from 'vs/editor/common/config/editorOptions';
import { monkeyPatchHttpAgent } from 'vs/platform/request/node/proxy';

import 'vs/workbench/api/common/extHost.common.services';
import 'vs/workbench/api/node/extHost.node.services';
Expand Down Expand Up @@ -284,6 +285,11 @@ function connectToRenderer(protocol: IMessagePassingProtocol): Promise<IRenderer
}

export async function startExtensionHostProcess(): Promise<void> {
/**
* Patch proxy agent into the http libraries.
* @author coder
*/
monkeyPatchHttpAgent()

// Print a console message when rejection isn't handled within N seconds. For details:
// see https://nodejs.org/api/process.html#process_event_unhandledrejection
Expand Down
Loading