mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 05:56:38 +08:00
[优化] 更新默认服务器块,添加 HTTPS 支持并启用 SSL 握手拒绝
This commit is contained in:
@@ -1222,7 +1222,22 @@ func renderConnectionUpgradeMap() string {
|
||||
}
|
||||
|
||||
func renderDefaultServerBlock() string {
|
||||
return " server {\n listen 80 default_server;\n server_name _;\n\n return 404;\n }\n\n"
|
||||
return strings.Join([]string{
|
||||
" server {",
|
||||
" listen 80 default_server;",
|
||||
" server_name _;",
|
||||
"",
|
||||
" return 404;",
|
||||
" }",
|
||||
"",
|
||||
" server {",
|
||||
" listen 443 ssl default_server;",
|
||||
" server_name _;",
|
||||
"",
|
||||
" ssl_reject_handshake on;",
|
||||
" }",
|
||||
"",
|
||||
}, "\n")
|
||||
}
|
||||
|
||||
func renderProxyHeaderBlock(originURL string, originHost string, customHeaders []ProxyRouteCustomHeaderInput, upstreamConfig routeUpstreamConfig) string {
|
||||
|
||||
@@ -949,12 +949,18 @@ func TestRenderConfigUsesDefaultServerFallback(t *testing.T) {
|
||||
if !strings.Contains(preview.MainConfig, "listen 80 default_server;") {
|
||||
t.Fatal("expected preview main config to include default http server")
|
||||
}
|
||||
if !strings.Contains(preview.MainConfig, "listen 443 ssl default_server;") {
|
||||
t.Fatal("expected preview main config to include default https server")
|
||||
}
|
||||
if !strings.Contains(preview.MainConfig, "server_name _;") {
|
||||
t.Fatal("expected preview main config to include default server_name")
|
||||
}
|
||||
if !strings.Contains(preview.MainConfig, "return 404;") {
|
||||
t.Fatal("expected preview main config to return 404 for unmatched hosts")
|
||||
}
|
||||
if !strings.Contains(preview.MainConfig, "ssl_reject_handshake on;") {
|
||||
t.Fatal("expected preview main config to reject unmatched https handshakes")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateTLSCertificateRejectsInvalidPEM(t *testing.T) {
|
||||
@@ -1007,6 +1013,12 @@ func TestOpenRestyMainConfigTemplateRenderAndValidate(t *testing.T) {
|
||||
if !strings.Contains(preview.MainConfig, "listen 80 default_server;") {
|
||||
t.Fatal("expected preview main config to preserve managed default server block")
|
||||
}
|
||||
if !strings.Contains(preview.MainConfig, "listen 443 ssl default_server;") {
|
||||
t.Fatal("expected preview main config to preserve managed default https server block")
|
||||
}
|
||||
if !strings.Contains(preview.MainConfig, "ssl_reject_handshake on;") {
|
||||
t.Fatal("expected preview main config to preserve managed https handshake rejection")
|
||||
}
|
||||
|
||||
invalidTemplate := strings.ReplaceAll(
|
||||
common.OpenRestyMainConfigTemplate,
|
||||
|
||||
Reference in New Issue
Block a user