From 9a269ac0ec8a8f5b7ab592d9349fdd850fceae50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E6=98=8E?= <83812544+Ed1s0nZ@users.noreply.github.com> Date: Mon, 20 Jul 2026 10:49:40 +0800 Subject: [PATCH] Add files via upload --- internal/config/server_https_bootstrap.go | 14 +++++++++ .../config/server_https_bootstrap_test.go | 31 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 internal/config/server_https_bootstrap_test.go diff --git a/internal/config/server_https_bootstrap.go b/internal/config/server_https_bootstrap.go index 80a4e4d2..6f67a601 100644 --- a/internal/config/server_https_bootstrap.go +++ b/internal/config/server_https_bootstrap.go @@ -44,3 +44,17 @@ func ApplyDevHTTPSBootstrap(cfg *Config) { } cfg.Server.TLSAutoSelfSign = true } + +// ApplyPlainHTTPBootstrap 供 --http / 一键脚本使用:强制主站使用明文 HTTP。 +// 它会覆盖配置文件中的 TLS 开关、自签证书以及证书路径,避免 --http 仍被配置中的 HTTPS 选项重新启用。 +func ApplyPlainHTTPBootstrap(cfg *Config) { + if cfg == nil { + return + } + cfg.Server.TLSEnabled = false + cfg.Server.TLSAutoSelfSign = false + cfg.Server.TLSCertPath = "" + cfg.Server.TLSKeyPath = "" + disabled := false + cfg.Server.TLSHTTPRedirect = &disabled +} diff --git a/internal/config/server_https_bootstrap_test.go b/internal/config/server_https_bootstrap_test.go new file mode 100644 index 00000000..0a7836ca --- /dev/null +++ b/internal/config/server_https_bootstrap_test.go @@ -0,0 +1,31 @@ +package config + +import "testing" + +func TestApplyPlainHTTPBootstrapDisablesConfiguredTLS(t *testing.T) { + enabled := true + cfg := &Config{ + Server: ServerConfig{ + TLSEnabled: true, + TLSAutoSelfSign: true, + TLSCertPath: "/tmp/server.crt", + TLSKeyPath: "/tmp/server.key", + TLSHTTPRedirect: &enabled, + }, + } + + ApplyPlainHTTPBootstrap(cfg) + + if MainWebUIUsesHTTPS(&cfg.Server) { + t.Fatal("expected --http bootstrap to disable main web UI HTTPS") + } + if ServerHTTPRedirectEnabled(&cfg.Server) { + t.Fatal("expected --http bootstrap to disable HTTP to HTTPS redirect") + } + if cfg.Server.TLSCertPath != "" || cfg.Server.TLSKeyPath != "" { + t.Fatalf("expected TLS cert paths to be cleared, got cert=%q key=%q", cfg.Server.TLSCertPath, cfg.Server.TLSKeyPath) + } + if cfg.Server.TLSHTTPRedirect == nil || *cfg.Server.TLSHTTPRedirect { + t.Fatal("expected TLSHTTPRedirect to be explicitly disabled") + } +}