From fdd48879959065a4a9a92e06ce520c3daf61f789 Mon Sep 17 00:00:00 2001 From: AlinsRan Date: Sat, 11 Oct 2025 16:18:01 +0800 Subject: [PATCH 1/2] fix(conformance-test): HTTPRouteQueryParamMatching (#2598) --- Makefile | 2 +- internal/adc/translator/httproute.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b8566cff..ee22519a 100644 --- a/Makefile +++ b/Makefile @@ -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" 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 diff --git a/internal/adc/translator/httproute.go b/internal/adc/translator/httproute.go index 1b1fe88b..96de29ad 100644 --- a/internal/adc/translator/httproute.go +++ b/internal/adc/translator/httproute.go @@ -736,7 +736,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 @@ -775,7 +775,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 From f0410c9b952c54c600cc1656a2128244744d72cd Mon Sep 17 00:00:00 2001 From: AlinsRan Date: Mon, 13 Oct 2025 14:26:08 +0800 Subject: [PATCH 2/2] fix(conformance-test): HTTPRoutePathRewrite (#2597) --- Makefile | 2 +- internal/adc/translator/httproute.go | 31 ++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index ee22519a..9504782e 100644 --- a/Makefile +++ b/Makefile @@ -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,HTTPRouteQueryParamMatching" +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 diff --git a/internal/adc/translator/httproute.go b/internal/adc/translator/httproute.go index 96de29ad..6983f2f5 100644 --- a/internal/adc/translator/httproute.go +++ b/internal/adc/translator/httproute.go @@ -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/" + // 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/" + // 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} } } }