|
1 | 1 | import { Api } from "coder/site/src/api/api" |
2 | 2 | import fs from "fs/promises" |
3 | | -import * as https from "https" |
4 | 3 | import * as os from "os" |
| 4 | +import { ProxyAgent } from "proxy-agent" |
| 5 | +import { getProxyForUrl } from "proxy-from-env" |
5 | 6 | import * as vscode from "vscode" |
6 | 7 | import { CertificateError } from "./error" |
7 | 8 | import { Storage } from "./storage" |
@@ -30,22 +31,28 @@ export async function makeCoderSdk(baseUrl: string, token: string | undefined, s |
30 | 31 | config.headers[key] = value |
31 | 32 | }) |
32 | 33 |
|
33 | | - // Configure TLS. |
34 | 34 | const cfg = vscode.workspace.getConfiguration() |
35 | 35 | const insecure = Boolean(cfg.get("coder.insecure")) |
36 | 36 | const certFile = expandPath(String(cfg.get("coder.tlsCertFile") ?? "").trim()) |
37 | 37 | const keyFile = expandPath(String(cfg.get("coder.tlsKeyFile") ?? "").trim()) |
38 | 38 | const caFile = expandPath(String(cfg.get("coder.tlsCaFile") ?? "").trim()) |
39 | 39 |
|
40 | | - config.httpsAgent = new https.Agent({ |
| 40 | + // Configure proxy and TLS. |
| 41 | + const agent = new ProxyAgent({ |
| 42 | + // If the proxy setting exists, we always use it. Otherwise we follow the |
| 43 | + // standard environment variables (no_proxy, http_proxy, etc). |
| 44 | + getProxyForUrl: (url: string) => cfg.get("http.proxy") || getProxyForUrl(url), |
41 | 45 | cert: certFile === "" ? undefined : await fs.readFile(certFile), |
42 | 46 | key: keyFile === "" ? undefined : await fs.readFile(keyFile), |
43 | 47 | ca: caFile === "" ? undefined : await fs.readFile(caFile), |
44 | | - // rejectUnauthorized defaults to true, so we need to explicitly set it to false |
45 | | - // if we want to allow self-signed certificates. |
| 48 | + // rejectUnauthorized defaults to true, so we need to explicitly set it to |
| 49 | + // false if we want to allow self-signed certificates. |
46 | 50 | rejectUnauthorized: !insecure, |
47 | 51 | }) |
48 | 52 |
|
| 53 | + config.httpsAgent = agent |
| 54 | + config.httpAgent = agent |
| 55 | + |
49 | 56 | return config |
50 | 57 | }) |
51 | 58 |
|
|
0 commit comments