From 485edbe9ac3f049d9bd3bfe9c6a36c63351ba127 Mon Sep 17 00:00:00 2001 From: Jesse Haka Date: Tue, 26 Mar 2024 12:32:20 +0200 Subject: [PATCH] allow websockets in url rewrite Signed-off-by: Jesse Haka --- internal/xds/translator/route.go | 10 ++++++++++ ...http-route-rewrite-root-path-url-prefix.routes.yaml | 2 ++ .../xds-ir/http-route-rewrite-url-fullpath.routes.yaml | 2 ++ .../out/xds-ir/http-route-rewrite-url-host.routes.yaml | 2 ++ .../xds-ir/http-route-rewrite-url-prefix.routes.yaml | 2 ++ 5 files changed, 18 insertions(+) diff --git a/internal/xds/translator/route.go b/internal/xds/translator/route.go index 22654bc8c45..6cb3e7259b7 100644 --- a/internal/xds/translator/route.go +++ b/internal/xds/translator/route.go @@ -59,6 +59,16 @@ func buildXdsRoute(httpRoute *ir.HTTPRoute) (*routev3.Route, error) { 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} default: var routeAction *routev3.RouteAction diff --git a/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-root-path-url-prefix.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-root-path-url-prefix.routes.yaml index 2bf01099ad2..d5a0bd98994 100644 --- a/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-root-path-url-prefix.routes.yaml +++ b/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-root-path-url-prefix.routes.yaml @@ -18,3 +18,5 @@ pattern: regex: ^/origin/\/* substitution: / + upgradeConfigs: + - upgradeType: websocket diff --git a/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-fullpath.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-fullpath.routes.yaml index f1f30bbbffc..f8b81712dae 100644 --- a/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-fullpath.routes.yaml +++ b/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-fullpath.routes.yaml @@ -14,3 +14,5 @@ pattern: regex: /.+ substitution: /rewrite + upgradeConfigs: + - upgradeType: websocket diff --git a/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-host.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-host.routes.yaml index 7de20ab0305..680a67404ee 100644 --- a/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-host.routes.yaml +++ b/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-host.routes.yaml @@ -17,3 +17,5 @@ cluster: rewrite-route-dest hostRewriteLiteral: 3.3.3.3 prefixRewrite: /rewrite + upgradeConfigs: + - upgradeType: websocket diff --git a/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-prefix.routes.yaml b/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-prefix.routes.yaml index a5f47ebab54..84bc70f04bd 100644 --- a/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-prefix.routes.yaml +++ b/internal/xds/translator/testdata/out/xds-ir/http-route-rewrite-url-prefix.routes.yaml @@ -15,3 +15,5 @@ route: cluster: rewrite-route-dest prefixRewrite: /rewrite + upgradeConfigs: + - upgradeType: websocket