@@ -15,18 +15,25 @@ import * as proxyagent from "proxy-agent"
15
15
*/
16
16
17
17
/**
18
- * monkeyPatch patches the node HTTP/HTTPS library to route all requests through our
19
- * custom agent from the proxyAgent package.
18
+ * monkeyPatch patches the node http and https modules to route all requests through the
19
+ * agent we get from the proxy-agent package.
20
+ *
21
+ * We do not support $HTTPS_PROXY here as it's equivalent in proxy-agent.
22
+ * See the mapping at https://www.npmjs.com/package/proxy-agent
23
+ *
24
+ * I guess with most proxies support both HTTP and HTTPS proxying on the same port and
25
+ * so two variables aren't required anymore. And there's plenty of SOCKS proxies too where
26
+ * it wouldn't make sense to have two variables.
27
+ *
28
+ * It's the most performant/secure setup as using a HTTP proxy for HTTP requests allows
29
+ * for caching but then using a HTTPS proxy for HTTPS requests gives full end to end
30
+ * security.
31
+ *
32
+ * See https://stackoverflow.com/a/10442767/4283659 for HTTP vs HTTPS proxy.
33
+ * To be clear, both support HTTP/HTTPS resources, the difference is in how they fetch
34
+ * them.
20
35
*/
21
36
export function monkeyPatch ( vscode : boolean ) : void {
22
- // We do not support HTTPS_PROXY here to avoid confusion. proxy-agent will automatically
23
- // use the correct protocol to connect to the proxy depending on the requested URL.
24
- //
25
- // We could implement support ourselves to allow people to configure the proxy used for
26
- // HTTPS vs HTTP but there doesn't seem to be much value in that.
27
- //
28
- // At least of right now, it'd just be plain confusing to support HTTPS_PROXY when proxy-agent
29
- // will still use HTTP to hit it for HTTP requests.
30
37
const proxyURL = process . env . HTTP_PROXY || process . env . http_proxy
31
38
if ( ! proxyURL ) {
32
39
return
@@ -47,14 +54,16 @@ export function monkeyPatch(vscode: boolean): void {
47
54
pa = new ( proxyagent as any ) . default ( proxyURL )
48
55
}
49
56
50
- /**
51
- * None of our code ever passes in a explicit agent to the http modules but VS Code's
52
- * does sometimes but only when a user sets the http.proxy configuration.
53
- * See https://code.visualstudio.com/docs/setup/network#_legacy-proxy-server-support
54
- *
55
- * Even if they do, it's probably the same proxy so we should be fine! And those are
56
- * deprecated anyway.
57
- */
57
+ // None of our code ever passes in a explicit agent to the http modules but VS Code's
58
+ // does sometimes but only when a user sets the http.proxy configuration.
59
+ // See https://code.visualstudio.com/docs/setup/network#_legacy-proxy-server-support
60
+ //
61
+ // Even if they do, it's probably the same proxy so we should be fine! And those are
62
+ // deprecated anyway. In fact, they implemented it incorrectly as they won't retrieve
63
+ // HTTPS resources over a HTTP proxy which is perfectly valid! Both HTTP and HTTPS proxies
64
+ // support HTTP/HTTPS resources.
65
+ //
66
+ // See https://stackoverflow.com/a/10442767/4283659
58
67
const http = require ( "http" )
59
68
const https = require ( "https" )
60
69
http . globalAgent = pa
0 commit comments