Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ GO_LDFLAGS ?= "-X=$(VERSYM)=$(VERSION) -X=$(GITSHASYM)=$(GITSHA) -X=$(BUILDOSSYM
# gateway-api
GATEAY_API_VERSION ?= v1.3.0
## https://github.com/kubernetes-sigs/gateway-api/blob/v1.3.0/pkg/features/httproute.go
<<<<<<< HEAD
SUPPORTED_EXTENDED_FEATURES = "HTTPRouteDestinationPortMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteRequestMirror,HTTPRouteSchemeRedirect,GatewayAddressEmpty,HTTPRouteResponseHeaderModification,GatewayPort8080"
=======
SUPPORTED_EXTENDED_FEATURES = "HTTPRouteDestinationPortMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteRequestMirror,HTTPRouteSchemeRedirect,GatewayAddressEmpty,HTTPRouteResponseHeaderModification,GatewayPort8080,HTTPRouteHostRewrite,HTTPRouteQueryParamMatching,HTTPRoutePathRewrite"
>>>>>>> 15132023 (fix(conformance-test): HTTPRoutePathRewrite (#2597))
CONFORMANCE_TEST_REPORT_OUTPUT ?= $(DIR)/apisix-ingress-controller-conformance-report.yaml
## https://github.com/kubernetes-sigs/gateway-api/blob/v1.3.0/conformance/utils/suite/profiles.go
CONFORMANCE_PROFILES ?= GATEWAY-HTTP,GATEWAY-GRPC
Expand Down
31 changes: 25 additions & 6 deletions internal/adc/translator/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,33 @@ func (t *Translator) fillPluginFromURLRewriteFilter(plugins adctypes.Plugins, ur
}
prefixPaths = append(prefixPaths, *match.Path.Value)
}
regexPattern := "^(" + strings.Join(prefixPaths, "|") + ")" + "/(.*)"
if len(prefixPaths) == 0 || urlRewrite.Path.ReplacePrefixMatch == nil {
break
}
prefixGroup := "(" + strings.Join(prefixPaths, "|") + ")"
replaceTarget := *urlRewrite.Path.ReplacePrefixMatch
regexTarget := replaceTarget + "/$2"

plugin.RewriteTargetRegex = []string{
regexPattern,
regexTarget,
// Handle ReplacePrefixMatch path rewrite
// If replaceTarget == "/", special handling is required to avoid
// producing double slashes or empty paths.
var regexPattern, regexTarget string
if replaceTarget == "/" {
// Match either "/prefix" or "/prefix/<remainder>"
// Pattern captures the remainder (if any) without a leading slash.
// Template reconstructs "/" + remainder, resulting in:
// /prefix/three → /three
// /prefix → /
regexPattern = "^" + prefixGroup + "(?:/(.*))?$"
regexTarget = "/" + "$2"
} else {
// Match either "/prefix" or "/prefix/<remainder>"
// Pattern captures the remainder (including leading slash) as $2.
// Template appends it to replaceTarget:
// /prefix/one/two → /one/two
// /prefix/one → /one
regexPattern = "^" + prefixGroup + "(/.*)?$"
regexTarget = replaceTarget + "$2"
}
plugin.RewriteTargetRegex = []string{regexPattern, regexTarget}
}
}
}
Expand Down
Loading