mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-10 17:26:38 +08:00
[优化] 添加 HTTP/3 支持配置选项
This commit is contained in:
@@ -152,6 +152,7 @@ type openRestyConfigSnapshot struct {
|
||||
ProxySendTimeout int `json:"proxy_send_timeout"`
|
||||
ProxyReadTimeout int `json:"proxy_read_timeout"`
|
||||
WebsocketEnabled bool `json:"websocket_enabled"`
|
||||
HTTP3Enabled bool `json:"http3_enabled"`
|
||||
ProxyRequestBuffering bool `json:"proxy_request_buffering"`
|
||||
ProxyBufferingEnabled bool `json:"proxy_buffering_enabled"`
|
||||
ProxyBuffers string `json:"proxy_buffers"`
|
||||
@@ -952,6 +953,7 @@ func buildOpenRestyConfigSnapshot() openRestyConfigSnapshot {
|
||||
ProxySendTimeout: common.OpenRestyProxySendTimeout,
|
||||
ProxyReadTimeout: common.OpenRestyProxyReadTimeout,
|
||||
WebsocketEnabled: common.OpenRestyWebsocketEnabled,
|
||||
HTTP3Enabled: common.OpenRestyHTTP3Enabled,
|
||||
ProxyRequestBuffering: common.OpenRestyProxyRequestBufferingEnabled,
|
||||
ProxyBufferingEnabled: common.OpenRestyProxyBufferingEnabled,
|
||||
ProxyBuffers: common.OpenRestyProxyBuffers,
|
||||
@@ -1071,6 +1073,7 @@ func diffOpenRestyOptionDetails(left openRestyConfigSnapshot, right openRestyCon
|
||||
appendIfChanged("OpenRestyProxySendTimeout", fmt.Sprintf("%d", left.ProxySendTimeout), fmt.Sprintf("%d", right.ProxySendTimeout))
|
||||
appendIfChanged("OpenRestyProxyReadTimeout", fmt.Sprintf("%d", left.ProxyReadTimeout), fmt.Sprintf("%d", right.ProxyReadTimeout))
|
||||
appendIfChanged("OpenRestyWebsocketEnabled", fmt.Sprintf("%t", left.WebsocketEnabled), fmt.Sprintf("%t", right.WebsocketEnabled))
|
||||
appendIfChanged("OpenRestyHTTP3Enabled", fmt.Sprintf("%t", left.HTTP3Enabled), fmt.Sprintf("%t", right.HTTP3Enabled))
|
||||
appendIfChanged("OpenRestyProxyRequestBufferingEnabled", fmt.Sprintf("%t", left.ProxyRequestBuffering), fmt.Sprintf("%t", right.ProxyRequestBuffering))
|
||||
appendIfChanged("OpenRestyProxyBufferingEnabled", fmt.Sprintf("%t", left.ProxyBufferingEnabled), fmt.Sprintf("%t", right.ProxyBufferingEnabled))
|
||||
appendIfChanged("OpenRestyProxyBuffers", left.ProxyBuffers, right.ProxyBuffers)
|
||||
@@ -1119,6 +1122,7 @@ func openRestyOptionKeys() []string {
|
||||
"OpenRestyProxySendTimeout",
|
||||
"OpenRestyProxyReadTimeout",
|
||||
"OpenRestyWebsocketEnabled",
|
||||
"OpenRestyHTTP3Enabled",
|
||||
"OpenRestyProxyRequestBufferingEnabled",
|
||||
"OpenRestyProxyBufferingEnabled",
|
||||
"OpenRestyProxyBuffers",
|
||||
|
||||
@@ -489,6 +489,9 @@ func TestPublishConfigVersionRendersMultipleCertificatesForMultiDomainWebsite(t
|
||||
|
||||
func TestPublishConfigVersionSkipsHTTPSForDomainsWithoutCertificate(t *testing.T) {
|
||||
setupServiceTestDB(t)
|
||||
if err := model.UpdateOption("OpenRestyHTTP3Enabled", "false"); err != nil {
|
||||
t.Fatalf("UpdateOption failed: %v", err)
|
||||
}
|
||||
|
||||
appCertPEM, appKeyPEM := generateCertificatePair(t, []string{"app.example.com"})
|
||||
appCertificate, err := CreateTLSCertificate(TLSCertificateInput{
|
||||
@@ -1338,6 +1341,80 @@ func TestOpenRestyProxyRequestBufferingDefaultsToOff(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreviewConfigVersionSupportsHTTP3(t *testing.T) {
|
||||
setupServiceTestDB(t)
|
||||
|
||||
appCertPEM, appKeyPEM := generateCertificatePair(t, []string{"h3.example.com"})
|
||||
appCertificate, err := CreateTLSCertificate(TLSCertificateInput{
|
||||
Name: "h3-cert",
|
||||
CertPEM: appCertPEM,
|
||||
KeyPEM: appKeyPEM,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateTLSCertificate failed: %v", err)
|
||||
}
|
||||
|
||||
_, err = CreateProxyRoute(ProxyRouteInput{
|
||||
SiteName: "h3-site",
|
||||
Domains: []string{"h3.example.com"},
|
||||
OriginURL: "https://origin.internal",
|
||||
Enabled: true,
|
||||
EnableHTTPS: true,
|
||||
CertID: &appCertificate.ID,
|
||||
DomainCertIDs: []uint{appCertificate.ID},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CreateProxyRoute failed: %v", err)
|
||||
}
|
||||
|
||||
if err := model.UpdateOption("OpenRestyHTTP3Enabled", "true"); err != nil {
|
||||
t.Fatalf("UpdateOption OpenRestyHTTP3Enabled failed: %v", err)
|
||||
}
|
||||
|
||||
preview, err := PreviewConfigVersion()
|
||||
if err != nil {
|
||||
t.Fatalf("PreviewConfigVersion failed: %v", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(preview.MainConfig, "listen 443 ssl default_server;\n listen 443 quic reuseport default_server;") {
|
||||
t.Fatalf("expected default server block to contain quic reuseport listener, main config: %s", preview.MainConfig)
|
||||
}
|
||||
|
||||
if !strings.Contains(preview.RenderedConfig, "listen 443 quic;") {
|
||||
t.Fatalf("expected routing server block to contain listen 443 quic, rendered config: %s", preview.RenderedConfig)
|
||||
}
|
||||
if !strings.Contains(preview.RenderedConfig, "add_header Alt-Svc 'h3=\":443\"; ma=86400';") {
|
||||
t.Fatalf("expected routing server block to contain Alt-Svc header, rendered config: %s", preview.RenderedConfig)
|
||||
}
|
||||
|
||||
if !strings.Contains(preview.RenderedConfig, "listen 443 ssl;") {
|
||||
t.Fatal("expected standard listen 443 ssl to be preserved")
|
||||
}
|
||||
if !strings.Contains(preview.RenderedConfig, "http2 on;") {
|
||||
t.Fatal("expected standard http2 on to be preserved")
|
||||
}
|
||||
|
||||
if err := model.UpdateOption("OpenRestyHTTP3Enabled", "false"); err != nil {
|
||||
t.Fatalf("UpdateOption OpenRestyHTTP3Enabled failed: %v", err)
|
||||
}
|
||||
|
||||
previewOff, err := PreviewConfigVersion()
|
||||
if err != nil {
|
||||
t.Fatalf("PreviewConfigVersion failed: %v", err)
|
||||
}
|
||||
|
||||
if strings.Contains(previewOff.MainConfig, "listen 443 quic reuseport default_server;") {
|
||||
t.Fatal("expected default server block to omit quic listener when disabled")
|
||||
}
|
||||
|
||||
if strings.Contains(previewOff.RenderedConfig, "listen 443 quic;") {
|
||||
t.Fatal("expected routing server block to omit quic listener when disabled")
|
||||
}
|
||||
if strings.Contains(previewOff.RenderedConfig, "add_header Alt-Svc") {
|
||||
t.Fatal("expected routing server block to omit Alt-Svc header when disabled")
|
||||
}
|
||||
}
|
||||
|
||||
func setupServiceTestDB(t *testing.T) {
|
||||
t.Helper()
|
||||
nodeAccessTokenCache.reset()
|
||||
|
||||
Reference in New Issue
Block a user