Skip to content

Commit

Permalink
Enable HTTPRouteRewritePath test
Browse files Browse the repository at this point in the history
Fixes: envoyproxy#2004

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg committed Oct 30, 2023
1 parent d65ab59 commit 96475fe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
19 changes: 16 additions & 3 deletions internal/xds/translator/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func buildXdsRoute(httpRoute *ir.HTTPRoute) *routev3.Route {
case httpRoute.Redirect != nil:
router.Action = &routev3.Route_Redirect{Redirect: buildXdsRedirectAction(httpRoute.Redirect)}
case httpRoute.URLRewrite != nil:
routeAction := buildXdsURLRewriteAction(httpRoute.Destination.Name, httpRoute.URLRewrite)
routeAction := buildXdsURLRewriteAction(httpRoute.Destination.Name, httpRoute.URLRewrite, httpRoute.PathMatch)
if httpRoute.Mirrors != nil {
routeAction.RequestMirrorPolicies = buildXdsRequestMirrorPolicies(httpRoute.Mirrors)
}
Expand Down Expand Up @@ -252,7 +252,7 @@ func buildXdsRedirectAction(redirection *ir.Redirect) *routev3.RedirectAction {
return routeAction
}

func buildXdsURLRewriteAction(destName string, urlRewrite *ir.URLRewrite) *routev3.RouteAction {
func buildXdsURLRewriteAction(destName string, urlRewrite *ir.URLRewrite, pathMatch *ir.StringMatch) *routev3.RouteAction {
routeAction := &routev3.RouteAction{
ClusterSpecifier: &routev3.RouteAction_Cluster{
Cluster: destName,
Expand All @@ -268,7 +268,20 @@ func buildXdsURLRewriteAction(destName string, urlRewrite *ir.URLRewrite) *route
Substitution: *urlRewrite.Path.FullReplace,
}
} else if urlRewrite.Path.PrefixMatchReplace != nil {
routeAction.PrefixRewrite = *urlRewrite.Path.PrefixMatchReplace
// Circumvent the case of "//" when the replace string is "/"
// An empty replace string does not seem to solve the issue so we are using
// a regex match and replace instead
if pathMatch != nil && pathMatch.Prefix != nil &&
(*urlRewrite.Path.PrefixMatchReplace == "" || *urlRewrite.Path.PrefixMatchReplace == "/") {
routeAction.RegexRewrite = &matcherv3.RegexMatchAndSubstitute{
Pattern: &matcherv3.RegexMatcher{
Regex: "^" + *pathMatch.Prefix,
},
Substitution: "",
}
} else {
routeAction.PrefixRewrite = *urlRewrite.Path.PrefixMatchReplace
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
name: rewrite-route
route:
cluster: rewrite-route-dest
prefixRewrite: /
regexRewrite:
pattern:
regex: ^/origin/
1 change: 0 additions & 1 deletion test/conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func TestGatewayAPIConformance(t *testing.T) {
CleanupBaseResources: *flags.CleanupBaseResources,
SupportedFeatures: suite.AllFeatures,
SkipTests: []string{
tests.HTTPRouteRewritePath.ShortName,
tests.GatewayStaticAddresses.ShortName,
tests.GatewayWithAttachedRoutes.ShortName,
tests.HTTPRouteBackendProtocolH2C.ShortName,
Expand Down
1 change: 0 additions & 1 deletion test/conformance/experimental_conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ func experimentalConformance(t *testing.T) {
CleanupBaseResources: *flags.CleanupBaseResources,
SupportedFeatures: suite.AllFeatures,
SkipTests: []string{
tests.HTTPRouteRewritePath.ShortName,
tests.GatewayStaticAddresses.ShortName,
tests.GatewayWithAttachedRoutes.ShortName,
tests.HTTPRouteBackendProtocolH2C.ShortName,
Expand Down

0 comments on commit 96475fe

Please sign in to comment.