Skip to content

Commit 1c0b7a5

Browse files
committed
fix: httproute matching
Signed-off-by: ashing <[email protected]>
1 parent d07a2ec commit 1c0b7a5

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

internal/provider/adc/translator/httproute.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,14 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
422422
case gatewayv1.PathMatchExact:
423423
route.Uris = []string{*match.Path.Value}
424424
case gatewayv1.PathMatchPathPrefix:
425-
route.Uris = []string{*match.Path.Value + "*"}
425+
pathValue := *match.Path.Value
426+
route.Uris = []string{pathValue}
427+
428+
if strings.HasSuffix(pathValue, "/") {
429+
route.Uris = append(route.Uris, pathValue+"*")
430+
} else {
431+
route.Uris = append(route.Uris, pathValue+"/*")
432+
}
426433
case gatewayv1.PathMatchRegularExpression:
427434
var this []adctypes.StringOrSlice
428435
this = append(this, adctypes.StringOrSlice{
@@ -439,6 +446,11 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
439446
default:
440447
return nil, errors.New("unknown path match type " + string(*match.Path.Type))
441448
}
449+
} else {
450+
/* If no matches are specified, the default is a prefix
451+
path match on "/", which has the effect of matching every
452+
HTTP request. */
453+
route.Uris = []string{"/", "/*"}
442454
}
443455

444456
if len(match.Headers) > 0 {
@@ -451,7 +463,12 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
451463
StrVal: "http_" + name,
452464
})
453465

454-
switch *header.Type {
466+
matchType := gatewayv1.HeaderMatchExact
467+
if header.Type != nil {
468+
matchType = *header.Type
469+
}
470+
471+
switch matchType {
455472
case gatewayv1.HeaderMatchExact:
456473
this = append(this, adctypes.StringOrSlice{
457474
StrVal: "==",
@@ -461,7 +478,7 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
461478
StrVal: "~~",
462479
})
463480
default:
464-
return nil, errors.New("unknown header match type " + string(*header.Type))
481+
return nil, errors.New("unknown header match type " + string(matchType))
465482
}
466483

467484
this = append(this, adctypes.StringOrSlice{
@@ -479,7 +496,12 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
479496
StrVal: "arg_" + strings.ToLower(fmt.Sprintf("%v", query.Name)),
480497
})
481498

482-
switch *query.Type {
499+
queryType := gatewayv1.QueryParamMatchExact
500+
if query.Type != nil {
501+
queryType = *query.Type
502+
}
503+
504+
switch queryType {
483505
case gatewayv1.QueryParamMatchExact:
484506
this = append(this, adctypes.StringOrSlice{
485507
StrVal: "==",
@@ -489,7 +511,7 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
489511
StrVal: "~~",
490512
})
491513
default:
492-
return nil, errors.New("unknown query match type " + string(*query.Type))
514+
return nil, errors.New("unknown query match type " + string(queryType))
493515
}
494516

495517
this = append(this, adctypes.StringOrSlice{

test/conformance/conformance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var skippedTestsForTraditionalRoutes = []string{
3737
tests.HTTPRouteHostnameIntersection.ShortName,
3838
tests.HTTPRouteListenerHostnameMatching.ShortName,
3939

40-
tests.HTTPRouteMatching.ShortName,
40+
// tests.HTTPRouteMatching.ShortName,
4141
tests.HTTPRouteMatchingAcrossRoutes.ShortName,
4242

4343
tests.GatewayInvalidTLSConfiguration.ShortName,

0 commit comments

Comments
 (0)