Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Support using the system network proxy https://github.com/siyuan-note/siyuan/issues/18819

Daniel511a5ffe9ae7
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.json
index ea5365eab7..03c30c1694 100644
--- a/app/appearance/langs/ar.json
+++ b/app/appearance/langs/ar.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "استخدام وكيل النظام",
"statusBarMsgSyncDataSnapshot": "مزامنة لقطة البيانات",
"entryDocumentStatistics": "إحصاءات المستند",
"entryTabMenu": "قائمة علامات التبويب",
diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.json
index 149333f3dc..ddaf5b1b86 100644
--- a/app/appearance/langs/de.json
+++ b/app/appearance/langs/de.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Systemproxy verwenden",
"statusBarMsgSyncDataSnapshot": "Datenschnappschuss synchronisieren",
"entryDocumentStatistics": "Dokumentstatistik",
"entryTabMenu": "Tab-Menü",
diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.json
index 568897d7e8..219ff6cd90 100644
--- a/app/appearance/langs/en.json
+++ b/app/appearance/langs/en.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Use system proxy",
"statusBarMsgSyncDataSnapshot": "Synchronize data snapshot",
"entryDocumentStatistics": "Document statistics",
"entryTabMenu": "Tab menu",
diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.json
index ca057cc900..74a69c0e69 100644
--- a/app/appearance/langs/es.json
+++ b/app/appearance/langs/es.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Usar proxy del sistema",
"statusBarMsgSyncDataSnapshot": "Sincronizar instantánea de datos",
"entryDocumentStatistics": "Estadísticas del documento",
"entryTabMenu": "Menú de pestañas",
diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.json
index dcb65c9182..d2bb81bdb8 100644
--- a/app/appearance/langs/fr.json
+++ b/app/appearance/langs/fr.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Utiliser le proxy système",
"statusBarMsgSyncDataSnapshot": "Synchroniser l'instantané des données",
"entryDocumentStatistics": "Statistiques du document",
"entryTabMenu": "Menu des onglets",
diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.json
index 8ff60fcaee..474f11a833 100644
--- a/app/appearance/langs/he.json
+++ b/app/appearance/langs/he.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "שימוש בשרת ה-Proxy של המערכת",
"statusBarMsgSyncDataSnapshot": "סנכרון צילום הנתונים",
"entryDocumentStatistics": "סטטיסטיקות מסמך",
"entryTabMenu": "תפריט כרטיסיות",
diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.json
index 32231e5f1e..a7566d93d9 100644
--- a/app/appearance/langs/hi.json
+++ b/app/appearance/langs/hi.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "सिस्टम प्रॉक्सी का उपयोग करें",
"statusBarMsgSyncDataSnapshot": "डेटा स्नैपशॉट सिंक करें",
"entryDocumentStatistics": "दस्तावेज़ के आँकड़े",
"entryTabMenu": "टैब मेनू",
diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.json
index 269c572cd4..ca06814822 100644
--- a/app/appearance/langs/id.json
+++ b/app/appearance/langs/id.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Gunakan proksi sistem",
"statusBarMsgSyncDataSnapshot": "Sinkronkan snapshot data",
"entryDocumentStatistics": "Statistik dokumen",
"entryTabMenu": "Menu tab",
diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.json
index 74b17bc681..62a8ffd5f0 100644
--- a/app/appearance/langs/it.json
+++ b/app/appearance/langs/it.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Usa proxy di sistema",
"statusBarMsgSyncDataSnapshot": "Sincronizza snapshot dei dati",
"entryDocumentStatistics": "Statistiche del documento",
"entryTabMenu": "Menu delle schede",
diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.json
index 31c582b115..2640d585ba 100644
--- a/app/appearance/langs/ja.json
+++ b/app/appearance/langs/ja.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "システムプロキシを使用",
"statusBarMsgSyncDataSnapshot": "データスナップショットを同期",
"entryDocumentStatistics": "ドキュメント統計",
"entryTabMenu": "タブメニュー",
diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.json
index 2e6996b9c7..3dde1cc1e2 100644
--- a/app/appearance/langs/ko.json
+++ b/app/appearance/langs/ko.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "시스템 프록시 사용",
"statusBarMsgSyncDataSnapshot": "데이터 스냅샷 동기화",
"entryDocumentStatistics": "문서 통계",
"entryTabMenu": "탭 메뉴",
diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.json
index d0035fec85..d2fa9a1708 100644
--- a/app/appearance/langs/nl.json
+++ b/app/appearance/langs/nl.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Systeemproxy gebruiken",
"statusBarMsgSyncDataSnapshot": "Gegevensmomentopname synchroniseren",
"entryDocumentStatistics": "Documentstatistieken",
"entryTabMenu": "Tabbladmenu",
diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.json
index aff9235885..da05f3e57a 100644
--- a/app/appearance/langs/pl.json
+++ b/app/appearance/langs/pl.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Użyj systemowego serwera proxy",
"statusBarMsgSyncDataSnapshot": "Synchronizuj zrzut danych",
"entryDocumentStatistics": "Statystyki dokumentu",
"entryTabMenu": "Menu kart",
diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.json
index 6cc84dcbd9..8b9af7b723 100644
--- a/app/appearance/langs/pt-BR.json
+++ b/app/appearance/langs/pt-BR.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Usar proxy do sistema",
"statusBarMsgSyncDataSnapshot": "Sincronizar snapshot de dados",
"entryDocumentStatistics": "Estatísticas do documento",
"entryTabMenu": "Menu de abas",
diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.json
index 7d217a058c..8566835dfe 100644
--- a/app/appearance/langs/ru.json
+++ b/app/appearance/langs/ru.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Использовать системный прокси",
"statusBarMsgSyncDataSnapshot": "Синхронизировать снимок данных",
"entryDocumentStatistics": "Статистика документа",
"entryTabMenu": "Меню вкладок",
diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.json
index 193c701e8b..480aff4715 100644
--- a/app/appearance/langs/sk.json
+++ b/app/appearance/langs/sk.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Použiť systémový proxy server",
"statusBarMsgSyncDataSnapshot": "Synchronizovať snímku údajov",
"entryDocumentStatistics": "Štatistiky dokumentu",
"entryTabMenu": "Ponuka kariet",
diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.json
index bd2c3a08f6..b091b83d66 100644
--- a/app/appearance/langs/th.json
+++ b/app/appearance/langs/th.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "ใช้พร็อกซีของระบบ",
"statusBarMsgSyncDataSnapshot": "ซิงค์สแนปช็อตข้อมูล",
"entryDocumentStatistics": "สถิติเอกสาร",
"entryTabMenu": "เมนูแท็บ",
diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.json
index fb2407768f..8204692a8f 100644
--- a/app/appearance/langs/tr.json
+++ b/app/appearance/langs/tr.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Sistem proxy'sini kullan",
"statusBarMsgSyncDataSnapshot": "Veri anlık görüntüsünü senkronize et",
"entryDocumentStatistics": "Belge istatistikleri",
"entryTabMenu": "Sekme menüsü",
diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.json
index 2dec66fa97..28df80a58d 100644
--- a/app/appearance/langs/uk.json
+++ b/app/appearance/langs/uk.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "Використовувати системний проксі",
"statusBarMsgSyncDataSnapshot": "Синхронізувати знімок даних",
"entryDocumentStatistics": "Статистика документа",
"entryTabMenu": "Меню вкладок",
diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.json
index 8944699a78..ea8550621d 100644
--- a/app/appearance/langs/zh-CN.json
+++ b/app/appearance/langs/zh-CN.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "使用系统代理",
"statusBarMsgSyncDataSnapshot": "同步数据快照",
"entryDocumentStatistics": "文档统计",
"entryTabMenu": "页签菜单",
diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.json
index a08e2f6fcb..455059f50a 100644
--- a/app/appearance/langs/zh-TW.json
+++ b/app/appearance/langs/zh-TW.json
@@ -1,4 +1,5 @@
{
+ "useSystemProxy": "使用系統代理",
"statusBarMsgSyncDataSnapshot": "同步資料快照",
"entryDocumentStatistics": "文件統計",
"entryTabMenu": "頁籤選單",
diff --git a/app/electron/main.js b/app/electron/main.js
index c1f1950eaa..5ee97509fa 100644
--- a/app/electron/main.js
+++ b/app/electron/main.js
@@ -346,10 +346,14 @@ const windowNavigate = (currentWindow, windowType) => {
};
const setProxy = (proxyURL, webContents) => {
- if (proxyURL.startsWith("://")) {
+ if (proxyURL.startsWith("system://")) {
console.log("network proxy [system]");
return webContents.session.setProxy({mode: "system"});
}
+ if (proxyURL.startsWith("://")) {
+ console.log("network proxy [direct]");
+ return webContents.session.setProxy({mode: "direct"});
+ }
console.log("network proxy [" + proxyURL + "]");
return webContents.session.setProxy({proxyRules: proxyURL});
};
diff --git a/app/src/config/tabs/appTab.ts b/app/src/config/tabs/appTab.ts
index 26e3a4d22a..402156ba27 100644
--- a/app/src/config/tabs/appTab.ts
+++ b/app/src/config/tabs/appTab.ts
@@ -205,6 +205,7 @@ const registerAppGeneralGroup = (tab: SettingTabBuilder) => {
window.siyuan.languages.networkProxy,
window.siyuan.languages.about17,
window.siyuan.languages.directConnection,
+ window.siyuan.languages.useSystemProxy,
"SOCKS5",
"HTTPS",
"HTTP",
@@ -227,6 +228,7 @@ const genNetworkProxyHtml = (): string => {
<div class="b3-label__text fn__flex config-wrap" style="overflow: visible !important;">
<select id="networkProxyScheme" class="b3-select">
<option value="" ${proxy.scheme === "" ? "selected" : ""}>${window.siyuan.languages.directConnection}</option>
+ <option value="system" ${proxy.scheme === "system" ? "selected" : ""}>${window.siyuan.languages.useSystemProxy}</option>
<option value="socks5" ${proxy.scheme === "socks5" ? "selected" : ""}>SOCKS5</option>
<option value="https" ${proxy.scheme === "https" ? "selected" : ""}>HTTPS</option>
<option value="http" ${proxy.scheme === "http" ? "selected" : ""}>HTTP</option>
@@ -242,10 +244,20 @@ const genNetworkProxyHtml = (): string => {
};
const mountNetworkProxy = (root: HTMLElement) => {
+ const schemeElement = root.querySelector("#networkProxyScheme") as HTMLSelectElement;
+ const hostElement = root.querySelector("#networkProxyHost") as HTMLInputElement;
+ const portElement = root.querySelector("#networkProxyPort") as HTMLInputElement;
+ const updateInputs = () => {
+ const disabled = schemeElement.value === "" || schemeElement.value === "system";
+ hostElement.disabled = disabled;
+ portElement.disabled = disabled;
+ };
+ schemeElement.addEventListener("change", updateInputs);
+ updateInputs();
root.querySelector("#networkProxyConfirm")?.addEventListener("click", () => {
- const scheme = (root.querySelector("#networkProxyScheme") as HTMLSelectElement)?.value as Config.TSystemNetworkProxyScheme;
- const host = (root.querySelector("#networkProxyHost") as HTMLInputElement)?.value;
- const port = (root.querySelector("#networkProxyPort") as HTMLInputElement)?.value;
+ const scheme = schemeElement.value as Config.TSystemNetworkProxyScheme;
+ const host = hostElement.value;
+ const port = portElement.value;
fetchPost("/api/system/setNetworkProxy", {scheme, host, port}, async () => {
Object.assign(window.siyuan.config.system.networkProxy, {scheme, host, port});
/// #if !BROWSER
diff --git a/app/src/types/config.d.ts b/app/src/types/config.d.ts
index d9c4cc404a..821ad7ced6 100644
--- a/app/src/types/config.d.ts
+++ b/app/src/types/config.d.ts
@@ -2030,7 +2030,8 @@ declare namespace Config {
port: string;
/**
* The protocol used by the proxy server
- * - Empty String: Use the system proxy settings
+ * - Empty String: Direct connection
+ * - `system`: Use the system proxy settings
* - `http`: HTTP
* - `https`: HTTPS
* - `socks5`: SOCKS5
@@ -2040,12 +2041,13 @@ declare namespace Config {
/**
* The protocol used by the proxy server
- * - Empty String: Use the system proxy settings
+ * - Empty String: Direct connection
+ * - `system`: Use the system proxy settings
* - `http`: HTTP
* - `https`: HTTPS
* - `socks5`: SOCKS5
*/
- export type TSystemNetworkProxyScheme = "" | "http" | "https" | "socks5";
+ export type TSystemNetworkProxyScheme = "" | "system" | "http" | "https" | "socks5";
/**
* The operating system name determined at compile time (obtained using the command `go tool
diff --git a/kernel/api/system.go b/kernel/api/system.go
index d3f84c0962..714fefa232 100644
--- a/kernel/api/system.go
+++ b/kernel/api/system.go
@@ -1465,7 +1465,7 @@ func setNetworkProxy(c *gin.Context) {
model.Conf.Save()
proxyURL := model.Conf.System.NetworkProxy.String()
- util.SetNetworkProxy(proxyURL)
+ util.SetNetworkProxy(proxyURL, model.Conf.System.NetworkProxy.IsSystem())
util.PushMsg(model.Conf.Language(102), 3000)
}
diff --git a/kernel/conf/system.go b/kernel/conf/system.go
index 8bf0031d23..ea4cc84e14 100644
--- a/kernel/conf/system.go
+++ b/kernel/conf/system.go
@@ -89,8 +89,12 @@ type NetworkProxy struct {
}
func (np *NetworkProxy) String() string {
- if "" == np.Scheme {
+ if "" == np.Scheme || "system" == np.Scheme {
return ""
}
return np.Scheme + "://" + np.Host + ":" + np.Port
}
+
+func (np *NetworkProxy) IsSystem() bool {
+ return "system" == np.Scheme
+}
diff --git a/kernel/conf/system_test.go b/kernel/conf/system_test.go
new file mode 100644
index 0000000000..6ca1f5d1db
--- /dev/null
+++ b/kernel/conf/system_test.go
@@ -0,0 +1,47 @@
+// SiYuan - From thought to insight, with agents
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package conf
+
+import "testing"
+
+func TestNetworkProxyString(t *testing.T) {
+ tests := []struct {
+ name string
+ proxy NetworkProxy
+ want string
+ }{
+ {name: "direct", proxy: NetworkProxy{}, want: ""},
+ {name: "system", proxy: NetworkProxy{Scheme: "system"}, want: ""},
+ {name: "configured", proxy: NetworkProxy{Scheme: "socks5", Host: "127.0.0.1", Port: "1080"}, want: "socks5://127.0.0.1:1080"},
+ }
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ if got := test.proxy.String(); got != test.want {
+ t.Fatalf("NetworkProxy.String() = %q, want %q", got, test.want)
+ }
+ })
+ }
+}
+
+func TestNetworkProxyIsSystem(t *testing.T) {
+ if !(&NetworkProxy{Scheme: "system"}).IsSystem() {
+ t.Fatal("system proxy should be detected")
+ }
+ if (&NetworkProxy{}).IsSystem() {
+ t.Fatal("direct connection should not be detected as system proxy")
+ }
+}
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index d5fcbf737b..00864a7a11 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -881,7 +881,7 @@ func InitConf() {
logging.SetLogLevel(Conf.LogLevel)
}
- util.SetNetworkProxy(Conf.System.NetworkProxy.String())
+ util.SetNetworkProxy(Conf.System.NetworkProxy.String(), Conf.System.NetworkProxy.IsSystem())
go util.InitPandoc(Conf.Export.PandocBin)
go util.InitTesseract()
diff --git a/kernel/util/openai.go b/kernel/util/openai.go
index 457674fad1..98052e3927 100644
--- a/kernel/util/openai.go
+++ b/kernel/util/openai.go
@@ -905,7 +905,7 @@ func downloadGeneratedImage(ctx context.Context, rawURL string) ([]byte, error)
func generatedImageHTTPClient() *http.Client {
return &http.Client{
Transport: &http.Transport{
- Proxy: http.ProxyFromEnvironment,
+ Proxy: httpclient.ProxyFromEnvironment,
DialContext: generatedImageDialer().DialContext,
},
CheckRedirect: func(req *http.Request, via []*http.Request) error {
diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go
index a26f12c487..9087028f6c 100644
--- a/kernel/util/runtime.go
+++ b/kernel/util/runtime.go
@@ -210,24 +210,58 @@ func GetDeviceName() string {
return ret
}
-func SetNetworkProxy(proxyURL string) {
- if err := os.Setenv("HTTPS_PROXY", proxyURL); err != nil {
- logging.LogErrorf("set env [HTTPS_PROXY] failed: %s", err)
- }
- if err := os.Setenv("HTTP_PROXY", proxyURL); err != nil {
- logging.LogErrorf("set env [HTTP_PROXY] failed: %s", err)
+func SetNetworkProxy(proxyURL string, useSystem bool) {
+ if useSystem {
+ restoreSystemNetworkProxyEnvironment()
+ } else {
+ for _, name := range networkProxyEnvironmentNames {
+ if err := os.Setenv(name, proxyURL); err != nil {
+ logging.LogErrorf("set env [%s] failed: %s", name, err)
+ }
+ }
}
- if "" != proxyURL {
+ if useSystem {
+ logging.LogInfof("use network proxy [system]")
+ } else if "" != proxyURL {
logging.LogInfof("use network proxy [%s]", networkProxyLogValue(proxyURL))
} else {
- logging.LogInfof("use network proxy [system]")
+ logging.LogInfof("use network proxy [direct]")
}
httpclient.CloseIdleConnections()
closeOpenAIIdleConnections()
}
+var networkProxyEnvironmentNames = []string{"HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy"}
+
+type networkProxyEnvironmentValue struct {
+ value string
+ set bool
+}
+
+var systemNetworkProxyEnvironment = func() map[string]networkProxyEnvironmentValue {
+ ret := make(map[string]networkProxyEnvironmentValue, len(networkProxyEnvironmentNames))
+ for _, name := range networkProxyEnvironmentNames {
+ value, set := os.LookupEnv(name)
+ ret[name] = networkProxyEnvironmentValue{value: value, set: set}
+ }
+ return ret
+}()
+
+func restoreSystemNetworkProxyEnvironment() {
+ for _, name := range networkProxyEnvironmentNames {
+ value := systemNetworkProxyEnvironment[name]
+ if value.set {
+ if err := os.Setenv(name, value.value); err != nil {
+ logging.LogErrorf("set env [%s] failed: %s", name, err)
+ }
+ } else if err := os.Unsetenv(name); err != nil {
+ logging.LogErrorf("unset env [%s] failed: %s", name, err)
+ }
+ }
+}
+
func networkProxyLogValue(rawURL string) string {
proxyURL, err := url.Parse(rawURL)
if err != nil {
diff --git a/kernel/util/runtime_test.go b/kernel/util/runtime_test.go
new file mode 100644
index 0000000000..b3fe3bd427
--- /dev/null
+++ b/kernel/util/runtime_test.go
@@ -0,0 +1,60 @@
+// SiYuan - From thought to insight, with agents
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package util
+
+import (
+ "os"
+ "testing"
+)
+
+func TestSetNetworkProxy(t *testing.T) {
+ for _, name := range networkProxyEnvironmentNames {
+ t.Setenv(name, os.Getenv(name))
+ }
+ original := systemNetworkProxyEnvironment
+ systemNetworkProxyEnvironment = map[string]networkProxyEnvironmentValue{
+ "HTTP_PROXY": {value: "http://system-http", set: true},
+ "HTTPS_PROXY": {value: "http://system-https", set: true},
+ "http_proxy": {value: "http://system-http", set: true},
+ "https_proxy": {value: "http://system-https", set: true},
+ }
+ t.Cleanup(func() {
+ systemNetworkProxyEnvironment = original
+ })
+
+ SetNetworkProxy("http://configured", false)
+ for _, name := range networkProxyEnvironmentNames {
+ if got := os.Getenv(name); got != "http://configured" {
+ t.Fatalf("%s = %q, want configured proxy", name, got)
+ }
+ }
+
+ SetNetworkProxy("", false)
+ for _, name := range networkProxyEnvironmentNames {
+ if got := os.Getenv(name); got != "" {
+ t.Fatalf("%s = %q, want direct connection", name, got)
+ }
+ }
+
+ SetNetworkProxy("", true)
+ if got := os.Getenv("HTTP_PROXY"); got != "http://system-http" {
+ t.Fatalf("HTTP_PROXY = %q, want system proxy", got)
+ }
+ if got := os.Getenv("HTTPS_PROXY"); got != "http://system-https" {
+ t.Fatalf("HTTPS_PROXY = %q, want system proxy", got)
+ }
+}