diff --git a/internal/gatewayapi/route.go b/internal/gatewayapi/route.go index fc4dac08cf5..c0821a94343 100644 --- a/internal/gatewayapi/route.go +++ b/internal/gatewayapi/route.go @@ -213,6 +213,7 @@ func (t *Translator) processHTTPRouteRules(httpRoute *HTTPRouteContext, parentRe StatusCode: 500, } } + ruleRoute.IsHTTP2 = false } // TODO handle: @@ -495,6 +496,7 @@ func (t *Translator) processGRPCRouteRules(grpcRoute *GRPCRouteContext, parentRe StatusCode: 500, } } + ruleRoute.IsHTTP2 = true } // TODO handle: @@ -658,6 +660,7 @@ func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, route ExtensionRefs: routeRoute.ExtensionRefs, Timeout: routeRoute.Timeout, Retry: routeRoute.Retry, + IsHTTP2: routeRoute.IsHTTP2, } // Don't bother copying over the weights unless the route has invalid backends. if routeRoute.BackendWeights.Invalid > 0 { diff --git a/internal/ir/xds.go b/internal/ir/xds.go index b6894482cac..d501fffac8f 100644 --- a/internal/ir/xds.go +++ b/internal/ir/xds.go @@ -413,6 +413,8 @@ type HTTPRoute struct { Name string `json:"name" yaml:"name"` // Hostname that the route matches against Hostname string `json:"hostname" yaml:"hostname,omitempty"` + // IsHTTP2 is set if the route is configured to serve HTTP2 traffic + IsHTTP2 bool `json:"isHTTP2" yaml:"isHTTP2"` // PathMatch defines the match conditions on the path. PathMatch *StringMatch `json:"pathMatch,omitempty" yaml:"pathMatch,omitempty"` // HeaderMatches define the match conditions on the request headers for this route. diff --git a/internal/xds/translator/listener.go b/internal/xds/translator/listener.go index 268cc1dd41c..40b6c0b2299 100644 --- a/internal/xds/translator/listener.go +++ b/internal/xds/translator/listener.go @@ -242,14 +242,6 @@ func (t *Translator) addXdsHTTPFilterChain(xdsListener *listenerv3.Listener, irL mgr.HttpFilters = append(mgr.HttpFilters, xdsfilters.GRPCWeb) // always enable grpc stats filter mgr.HttpFilters = append(mgr.HttpFilters, xdsfilters.GRPCStats) - } else { - // Allow websocket upgrades for HTTP 1.1 - // Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism - mgr.UpgradeConfigs = []*hcmv3.HttpConnectionManager_UpgradeConfig{ - { - UpgradeType: "websocket", - }, - } } if http3Listener { diff --git a/internal/xds/translator/route.go b/internal/xds/translator/route.go index c711e64daf5..1ab91bb6e89 100644 --- a/internal/xds/translator/route.go +++ b/internal/xds/translator/route.go @@ -57,20 +57,27 @@ func buildXdsRoute(httpRoute *ir.HTTPRoute) (*routev3.Route, error) { router.Action = &routev3.Route_Route{Route: routeAction} default: + routeAction := buildXdsRouteAction(httpRoute.Destination.Name) + if httpRoute.Mirrors != nil { + routeAction.RequestMirrorPolicies = buildXdsRequestMirrorPolicies(httpRoute.Mirrors) + } if httpRoute.BackendWeights.Invalid != 0 { // If there are invalid backends then a weighted cluster is required for the route - routeAction := buildXdsWeightedRouteAction(httpRoute) + routeAction = buildXdsWeightedRouteAction(httpRoute) if httpRoute.Mirrors != nil { routeAction.RequestMirrorPolicies = buildXdsRequestMirrorPolicies(httpRoute.Mirrors) } - router.Action = &routev3.Route_Route{Route: routeAction} - } else { - routeAction := buildXdsRouteAction(httpRoute.Destination.Name) - if httpRoute.Mirrors != nil { - routeAction.RequestMirrorPolicies = buildXdsRequestMirrorPolicies(httpRoute.Mirrors) + } + if !httpRoute.IsHTTP2 { + // Allow websocket upgrades for HTTP 1.1 + // Reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism + routeAction.UpgradeConfigs = []*routev3.RouteAction_UpgradeConfig{ + { + UpgradeType: "websocket", + }, } - router.Action = &routev3.Route_Route{Route: routeAction} } + router.Action = &routev3.Route_Route{Route: routeAction} } // Hash Policy