feat(proxy-route): allow disabling HTTP/2 per route

This commit is contained in:
ryan
2026-10-07 10:30:16 +08:00
parent 0bebca2990
commit 7ad25f61aa
20 changed files with 100 additions and 14 deletions
@@ -444,6 +444,7 @@ func snapshotPagesDeploymentEqual(left, right *openrestyrender.PagesDeployment)
func snapshotRoutePolicyEqual(left, right snapshotRoute) bool {
return left.EnableHTTPS == right.EnableHTTPS &&
left.EnableHTTP2 == right.EnableHTTP2 &&
left.RedirectHTTP == right.RedirectHTTP &&
left.LimitConnPerServer == right.LimitConnPerServer &&
left.LimitConnPerIP == right.LimitConnPerIP &&
@@ -50,6 +50,7 @@ type snapshotRoute struct {
Upstreams []string `json:"upstreams,omitempty"`
Enabled bool `json:"enabled"`
EnableHTTPS bool `json:"enable_https"`
EnableHTTP2 bool `json:"enable_http2"`
DomainCertIDs []uint `json:"domain_cert_ids,omitempty"`
RedirectHTTP bool `json:"redirect_http"`
LimitConnPerServer int `json:"limit_conn_per_server,omitempty"`
@@ -288,6 +289,7 @@ func buildSnapshotRoutes(ctx context.Context, routes []*model.ProxyRoute) ([]sna
Upstreams: upstreams,
Enabled: route.Enabled,
EnableHTTPS: route.EnableHTTPS,
EnableHTTP2: route.EnableHTTP2,
DomainCertIDs: domainCertIDs,
RedirectHTTP: route.RedirectHTTP,
LimitConnPerServer: route.LimitConnPerServer,
@@ -113,6 +113,14 @@ func populateProxyRouteFields(
route.UpstreamType = upstreamType
}
func applyProxyRouteHTTP2(route *model.ProxyRoute, input Input) {
if input.EnableHTTP2 != nil {
route.EnableHTTP2 = *input.EnableHTTP2
} else if route.ID == 0 {
route.EnableHTTP2 = true
}
}
func applyProxyRouteUpstreamType(ctx context.Context, route *model.ProxyRoute, upstreamType string, input Input) error {
switch upstreamType {
case proxyRouteUpstreamTypeTunnel:
@@ -35,6 +35,7 @@ type Input struct {
Upstreams []string `json:"upstreams"`
Enabled bool `json:"enabled"`
EnableHTTPS bool `json:"enable_https"`
EnableHTTP2 *bool `json:"enable_http2"`
RedirectHTTP bool `json:"redirect_http"`
LimitConnPerServer int `json:"limit_conn_per_server"`
LimitConnPerIP int `json:"limit_conn_per_ip"`
@@ -68,6 +69,7 @@ type View struct {
UpstreamList []string `json:"upstream_list"`
Enabled bool `json:"enabled"`
EnableHTTPS bool `json:"enable_https"`
EnableHTTP2 bool `json:"enable_http2"`
RedirectHTTP bool `json:"redirect_http"`
LimitConnPerServer int `json:"limit_conn_per_server"`
LimitConnPerIP int `json:"limit_conn_per_ip"`
@@ -310,6 +312,7 @@ func buildProxyRoute(ctx context.Context, route *model.ProxyRoute, input Input)
if route == nil {
route = &model.ProxyRoute{}
}
applyProxyRouteHTTP2(route, input)
populateProxyRouteFields(
route,
input,
@@ -381,6 +384,7 @@ func buildProxyRouteView(ctx context.Context, route *model.ProxyRoute) (*View, e
UpstreamList: upstreams,
Enabled: route.Enabled,
EnableHTTPS: route.EnableHTTPS,
EnableHTTP2: route.EnableHTTP2,
RedirectHTTP: route.RedirectHTTP,
LimitConnPerServer: route.LimitConnPerServer,
LimitConnPerIP: route.LimitConnPerIP,
@@ -0,0 +1,5 @@
-- +goose Up
ALTER TABLE of_proxy_routes ADD COLUMN enable_http2 BOOLEAN NOT NULL DEFAULT TRUE;
-- +goose Down
ALTER TABLE of_proxy_routes DROP COLUMN enable_http2;
@@ -0,0 +1,5 @@
-- +goose Up
ALTER TABLE of_proxy_routes ADD COLUMN enable_http2 BOOLEAN NOT NULL DEFAULT TRUE;
-- +goose Down
ALTER TABLE of_proxy_routes DROP COLUMN enable_http2;
+1
View File
@@ -18,6 +18,7 @@ type ProxyRoute struct {
Upstreams string `json:"upstreams" gorm:"type:text;not null;default:'[]'"`
Enabled bool `json:"enabled" gorm:"not null;default:true"`
EnableHTTPS bool `json:"enable_https" gorm:"column:enable_https;not null;default:false"`
EnableHTTP2 bool `json:"enable_http2" gorm:"not null;default:true"`
RedirectHTTP bool `json:"redirect_http" gorm:"not null;default:false"`
LimitConnPerServer int `json:"limit_conn_per_server" gorm:"not null;default:0"`
LimitConnPerIP int `json:"limit_conn_per_ip" gorm:"not null;default:0"`