From c74bd4403b7bd0a8b198cb20f088457088683820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E6=98=8E?= <83812544+Ed1s0nZ@users.noreply.github.com> Date: Fri, 15 May 2026 14:16:04 +0800 Subject: [PATCH] Add files via upload --- internal/config/config.go | 2 ++ internal/config/server_https_bootstrap.go | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/internal/config/config.go b/internal/config/config.go index 44890e2a..08105ab9 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -453,6 +453,8 @@ type ServerConfig struct { TLSKeyPath string `yaml:"tls_key_path,omitempty" json:"tls_key_path,omitempty"` // TLSAutoSelfSign 为 true 且未配置有效证书路径时,启动时生成内存自签证书(仅本地/测试;浏览器会提示不受信任)。 TLSAutoSelfSign bool `yaml:"tls_auto_self_sign,omitempty" json:"tls_auto_self_sign,omitempty"` + // TLSHTTPRedirect 为 false 时禁用 HTTP→HTTPS 跳转;省略或为 true 且已启用 HTTPS 时,明文 HTTP 访问将 308 跳转到 HTTPS(同端口嗅探分流)。 + TLSHTTPRedirect *bool `yaml:"tls_http_redirect,omitempty" json:"tls_http_redirect,omitempty"` } type LogConfig struct { diff --git a/internal/config/server_https_bootstrap.go b/internal/config/server_https_bootstrap.go index 4aaa8965..80a4e4d2 100644 --- a/internal/config/server_https_bootstrap.go +++ b/internal/config/server_https_bootstrap.go @@ -18,6 +18,17 @@ func MainWebUIUsesHTTPS(s *ServerConfig) bool { return cert != "" && key != "" } +// ServerHTTPRedirectEnabled 是否在主站启用 HTTPS 时把明文 HTTP 请求重定向到 HTTPS(默认开启)。 +func ServerHTTPRedirectEnabled(s *ServerConfig) bool { + if s == nil || !MainWebUIUsesHTTPS(s) { + return false + } + if s.TLSHTTPRedirect == nil { + return true + } + return *s.TLSHTTPRedirect +} + // ApplyDevHTTPSBootstrap 供 --https / 一键脚本使用:强制开启主站 TLS。 // 若已配置 tls_cert_path 与 tls_key_path 则仅用 PEM,不开启自签;否则启用 tls_auto_self_sign(内存证书,仅本地测试)。 func ApplyDevHTTPSBootstrap(cfg *Config) {