Support RegularExpression for path matching
This commit is contained in:
parent
0e215f9b61
commit
6e61fe0de1
4 changed files with 30 additions and 1 deletions
|
@ -273,7 +273,7 @@ Kubernetes cluster before creating `HTTPRoute` objects.
|
||||||
| [6] | `rules` | A list of HTTP matchers, filters and actions. |
|
| [6] | `rules` | A list of HTTP matchers, filters and actions. |
|
||||||
| [7] | `matches` | Conditions used for matching the rule against incoming HTTP requests. Each match is independent, i.e. this rule will be matched if **any** one of the matches is satisfied. |
|
| [7] | `matches` | Conditions used for matching the rule against incoming HTTP requests. Each match is independent, i.e. this rule will be matched if **any** one of the matches is satisfied. |
|
||||||
| [8] | `path` | An HTTP request path matcher. If this field is not specified, a default prefix match on the "/" path is provided. |
|
| [8] | `path` | An HTTP request path matcher. If this field is not specified, a default prefix match on the "/" path is provided. |
|
||||||
| [9] | `type` | Type of match against the path Value (supported types: `Exact`, `PathPrefix`). |
|
| [9] | `type` | Type of match against the path Value (supported types: `Exact`, `PathPrefix`, and `RegularExpression`). |
|
||||||
| [10] | `value` | The value of the HTTP path to match against. |
|
| [10] | `value` | The value of the HTTP path to match against. |
|
||||||
| [11] | `headers` | Conditions to select a HTTP route by matching HTTP request headers. |
|
| [11] | `headers` | Conditions to select a HTTP route by matching HTTP request headers. |
|
||||||
| [12] | `name` | Name of the HTTP header to be matched. |
|
| [12] | `name` | Name of the HTTP header to be matched. |
|
||||||
|
|
|
@ -68,3 +68,14 @@ spec:
|
||||||
weight: 1
|
weight: 1
|
||||||
kind: Service
|
kind: Service
|
||||||
group: ""
|
group: ""
|
||||||
|
|
||||||
|
- matches:
|
||||||
|
- path:
|
||||||
|
type: RegularExpression
|
||||||
|
value: "^/buzz/[0-9]+$"
|
||||||
|
backendRefs:
|
||||||
|
- name: whoami
|
||||||
|
port: 80
|
||||||
|
weight: 1
|
||||||
|
kind: Service
|
||||||
|
group: ""
|
||||||
|
|
|
@ -1894,6 +1894,8 @@ func extractRule(routeRule gatev1.HTTPRouteRule, hostRule string) (string, error
|
||||||
matchRules = append(matchRules, fmt.Sprintf("Path(`%s`)", *match.Path.Value))
|
matchRules = append(matchRules, fmt.Sprintf("Path(`%s`)", *match.Path.Value))
|
||||||
case gatev1.PathMatchPathPrefix:
|
case gatev1.PathMatchPathPrefix:
|
||||||
matchRules = append(matchRules, buildPathMatchPathPrefixRule(*match.Path.Value))
|
matchRules = append(matchRules, buildPathMatchPathPrefixRule(*match.Path.Value))
|
||||||
|
case gatev1.PathMatchRegularExpression:
|
||||||
|
matchRules = append(matchRules, fmt.Sprintf("PathRegexp(`%s`)", *match.Path.Value))
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("unsupported path match type %s", *match.Path.Type)
|
return "", fmt.Errorf("unsupported path match type %s", *match.Path.Type)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1300,6 +1300,12 @@ func TestLoadHTTPRoutes(t *testing.T) {
|
||||||
Rule: "Host(`foo.com`) && Path(`/bar`) && Header(`my-header`,`bar`)",
|
Rule: "Host(`foo.com`) && Path(`/bar`) && Header(`my-header`,`bar`)",
|
||||||
RuleSyntax: "v3",
|
RuleSyntax: "v3",
|
||||||
},
|
},
|
||||||
|
"default-http-app-1-my-gateway-web-d23f7039bc8036fb918c": {
|
||||||
|
EntryPoints: []string{"web"},
|
||||||
|
Service: "default-http-app-1-my-gateway-web-d23f7039bc8036fb918c-wrr",
|
||||||
|
Rule: "Host(`foo.com`) && PathRegexp(`^/buzz/[0-9]+$`)",
|
||||||
|
RuleSyntax: "v3",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*dynamic.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*dynamic.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
|
@ -1323,6 +1329,16 @@ func TestLoadHTTPRoutes(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"default-http-app-1-my-gateway-web-d23f7039bc8036fb918c-wrr": {
|
||||||
|
Weighted: &dynamic.WeightedRoundRobin{
|
||||||
|
Services: []dynamic.WRRService{
|
||||||
|
{
|
||||||
|
Name: "default-whoami-80",
|
||||||
|
Weight: func(i int) *int { return &i }(1),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
"default-whoami-80": {
|
"default-whoami-80": {
|
||||||
LoadBalancer: &dynamic.ServersLoadBalancer{
|
LoadBalancer: &dynamic.ServersLoadBalancer{
|
||||||
Servers: []dynamic.Server{
|
Servers: []dynamic.Server{
|
||||||
|
|
Loading…
Reference in a new issue