diff --git a/pkg/ingress/config/ingress_config.go b/pkg/ingress/config/ingress_config.go index 61c56fe75..d77c8416c 100644 --- a/pkg/ingress/config/ingress_config.go +++ b/pkg/ingress/config/ingress_config.go @@ -482,6 +482,9 @@ func (m *IngressConfig) convertVirtualService(configs []common.WrapperConfig) [] vs := wrapperVS.VirtualService vs.Gateways = gateways + // Sort, exact -> prefix -> regex + common.SortHTTPRoutes(routes) + for _, route := range routes { vs.Http = append(vs.Http, route.HTTPRoute) } diff --git a/pkg/ingress/kube/common/tool.go b/pkg/ingress/kube/common/tool.go index 8c3257970..81828dab4 100644 --- a/pkg/ingress/kube/common/tool.go +++ b/pkg/ingress/kube/common/tool.go @@ -170,7 +170,14 @@ func SortHTTPRoutes(routes []*WrapperHTTPRoute) { isAllCatch := func(route *WrapperHTTPRoute) bool { if route.OriginPathType == Prefix && route.OriginPath == "/" { - return true + if route.HTTPRoute.Match == nil { + return true + } + + match := route.HTTPRoute.Match[0] + if len(match.Headers) == 0 && len(match.QueryParams) == 0 && match.Method == nil { + return true + } } return false } diff --git a/pkg/ingress/kube/ingressv1/controller.go b/pkg/ingress/kube/ingressv1/controller.go index c170e41ec..dfe319c39 100644 --- a/pkg/ingress/kube/ingressv1/controller.go +++ b/pkg/ingress/kube/ingressv1/controller.go @@ -599,11 +599,6 @@ func (c *controller) ConvertHTTPRoute(convertOptions *common.ConvertOptions, wra } else { convertOptions.HTTPRoutes[rule.Host] = wrapperHttpRoutes } - - // Sort, exact -> prefix -> regex - routes := convertOptions.HTTPRoutes[rule.Host] - IngressLog.Debugf("routes of host %s is %v", rule.Host, routes) - common.SortHTTPRoutes(routes) } return nil diff --git a/test/e2e/conformance/tests/httproute-same-host-and-path.go b/test/e2e/conformance/tests/httproute-same-host-and-path.go index e65cefb37..46a88f125 100644 --- a/test/e2e/conformance/tests/httproute-same-host-and-path.go +++ b/test/e2e/conformance/tests/httproute-same-host-and-path.go @@ -90,6 +90,25 @@ var HTTPRouteSameHostAndPath = suite.ConformanceTest{ }, }, }, + { + Meta: http.AssertionMeta{ + TargetBackend: "infra-backend-v2", + TargetNamespace: "higress-conformance-infra", + }, + Request: http.AssertionRequest{ + ActualRequest: http.Request{ + Path: "/", + Headers: map[string]string{ + "abc": "123", + }, + }, + }, + Response: http.AssertionResponse{ + ExpectedResponse: http.Response{ + StatusCode: 200, + }, + }, + }, } t.Run("Match Routes With same host and path", func(t *testing.T) { diff --git a/test/e2e/conformance/tests/httproute-same-host-and-path.yaml b/test/e2e/conformance/tests/httproute-same-host-and-path.yaml index 8f77f64d4..79ecd7fa0 100644 --- a/test/e2e/conformance/tests/httproute-same-host-and-path.yaml +++ b/test/e2e/conformance/tests/httproute-same-host-and-path.yaml @@ -102,3 +102,42 @@ spec: name: infra-backend-v2 port: number: 8080 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: higress-same-host-and-path-05 + namespace: higress-conformance-infra +spec: + ingressClassName: higress + rules: + - http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: infra-backend-v1 + port: + number: 8080 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + # exact matching + higress.io/exact-match-header-abc: "123" + name: higress-same-host-and-path-06 + namespace: higress-conformance-infra +spec: + ingressClassName: higress + rules: + - http: + paths: + - pathType: Prefix + path: "/" + backend: + service: + name: infra-backend-v2 + port: + number: 8080