Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ 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
SUPPORTED_EXTENDED_FEATURES = "HTTPRouteDestinationPortMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteRequestMirror,HTTPRouteSchemeRedirect,GatewayAddressEmpty,HTTPRouteResponseHeaderModification,GatewayPort8080,HTTPRouteHostRewrite"
SUPPORTED_EXTENDED_FEATURES = "HTTPRouteDestinationPortMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteRequestMirror,HTTPRouteSchemeRedirect,GatewayAddressEmpty,HTTPRouteResponseHeaderModification,GatewayPort8080,HTTPRouteHostRewrite,HTTPRouteQueryParamMatching,HTTPRoutePathRewrite"
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
34 changes: 26 additions & 8 deletions internal/adc/translator/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,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 Expand Up @@ -736,7 +755,7 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
for _, query := range match.QueryParams {
var this []adctypes.StringOrSlice
this = append(this, adctypes.StringOrSlice{
StrVal: "arg_" + strings.ToLower(fmt.Sprintf("%v", query.Name)),
StrVal: "arg_" + fmt.Sprintf("%v", query.Name),
})

queryType := gatewayv1.QueryParamMatchExact
Expand Down Expand Up @@ -775,7 +794,6 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
}

func HeaderMatchToVars(matchType, name, value string) ([]adctypes.StringOrSlice, error) {
name = strings.ToLower(name)
name = strings.ReplaceAll(name, "-", "_")

var this []adctypes.StringOrSlice
Expand Down
Loading