Skip to content

Commit a8bdd8d

Browse files
committed
Merge remote-tracking branch 'origin/master' into backport/1afb9ac-to-master
2 parents c8737cd + bb9e53d commit a8bdd8d

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ GO_LDFLAGS ?= "-X=$(VERSYM)=$(VERSION) -X=$(GITSHASYM)=$(GITSHA) -X=$(BUILDOSSYM
5959
# gateway-api
6060
GATEAY_API_VERSION ?= v1.3.0
6161
## https://github.com/kubernetes-sigs/gateway-api/blob/v1.3.0/pkg/features/httproute.go
62-
SUPPORTED_EXTENDED_FEATURES = "HTTPRouteDestinationPortMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteRequestMirror,HTTPRouteSchemeRedirect,GatewayAddressEmpty,HTTPRouteResponseHeaderModification,GatewayPort8080,HTTPRouteHostRewrite"
62+
SUPPORTED_EXTENDED_FEATURES = "HTTPRouteDestinationPortMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteRequestMirror,HTTPRouteSchemeRedirect,GatewayAddressEmpty,HTTPRouteResponseHeaderModification,GatewayPort8080,HTTPRouteHostRewrite,HTTPRouteQueryParamMatching,HTTPRoutePathRewrite"
6363
CONFORMANCE_TEST_REPORT_OUTPUT ?= $(DIR)/apisix-ingress-controller-conformance-report.yaml
6464
## https://github.com/kubernetes-sigs/gateway-api/blob/v1.3.0/conformance/utils/suite/profiles.go
6565
CONFORMANCE_PROFILES ?= GATEWAY-HTTP,GATEWAY-GRPC,GATEWAY-TLS

internal/adc/translator/httproute.go

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,33 @@ func (t *Translator) fillPluginFromURLRewriteFilter(plugins adctypes.Plugins, ur
119119
}
120120
prefixPaths = append(prefixPaths, *match.Path.Value)
121121
}
122-
regexPattern := "^(" + strings.Join(prefixPaths, "|") + ")" + "/(.*)"
122+
if len(prefixPaths) == 0 || urlRewrite.Path.ReplacePrefixMatch == nil {
123+
break
124+
}
125+
prefixGroup := "(" + strings.Join(prefixPaths, "|") + ")"
123126
replaceTarget := *urlRewrite.Path.ReplacePrefixMatch
124-
regexTarget := replaceTarget + "/$2"
125-
126-
plugin.RewriteTargetRegex = []string{
127-
regexPattern,
128-
regexTarget,
127+
// Handle ReplacePrefixMatch path rewrite
128+
// If replaceTarget == "/", special handling is required to avoid
129+
// producing double slashes or empty paths.
130+
var regexPattern, regexTarget string
131+
if replaceTarget == "/" {
132+
// Match either "/prefix" or "/prefix/<remainder>"
133+
// Pattern captures the remainder (if any) without a leading slash.
134+
// Template reconstructs "/" + remainder, resulting in:
135+
// /prefix/three → /three
136+
// /prefix → /
137+
regexPattern = "^" + prefixGroup + "(?:/(.*))?$"
138+
regexTarget = "/" + "$2"
139+
} else {
140+
// Match either "/prefix" or "/prefix/<remainder>"
141+
// Pattern captures the remainder (including leading slash) as $2.
142+
// Template appends it to replaceTarget:
143+
// /prefix/one/two → /one/two
144+
// /prefix/one → /one
145+
regexPattern = "^" + prefixGroup + "(/.*)?$"
146+
regexTarget = replaceTarget + "$2"
129147
}
148+
plugin.RewriteTargetRegex = []string{regexPattern, regexTarget}
130149
}
131150
}
132151
}
@@ -736,7 +755,7 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
736755
for _, query := range match.QueryParams {
737756
var this []adctypes.StringOrSlice
738757
this = append(this, adctypes.StringOrSlice{
739-
StrVal: "arg_" + strings.ToLower(fmt.Sprintf("%v", query.Name)),
758+
StrVal: "arg_" + fmt.Sprintf("%v", query.Name),
740759
})
741760

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

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

781799
var this []adctypes.StringOrSlice

0 commit comments

Comments
 (0)