Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/adc/translator/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,10 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa
})

route.Vars = append(route.Vars, this)
// APISIX Admin API requires uris to be a non-null array. Use "/*"
// as a catch-all so APISIX accepts the route; the vars entry above
// performs the actual regex filtering.
route.Uris = []string{"/*"}
default:
return nil, errors.New("unknown path match type " + string(*match.Path.Type))
}
Expand Down
54 changes: 54 additions & 0 deletions test/e2e/gatewayapi/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,60 @@ spec:
})
})

It("HTTPRoute RegularExpression Match", func() {
var regexRoute = fmt.Sprintf(`
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: httpbin
spec:
parentRefs:
- name: %s
hostnames:
- httpbin.example
rules:
- matches:
- path:
type: RegularExpression
value: /status/[0-9]+
backendRefs:
- name: httpbin-service-e2e-test
port: 80
`, s.Namespace())

By("create HTTPRoute with RegularExpression path type")
s.ResourceApplied("HTTPRoute", "httpbin", regexRoute, 1)

By("access dataplane: path matching regex should succeed")
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/status/200",
Host: "httpbin.example",
Check: scaffold.WithExpectedStatus(http.StatusOK),
Timeout: time.Second * 30,
Interval: time.Second * 2,
})

s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/status/201",
Host: "httpbin.example",
Check: scaffold.WithExpectedStatus(http.StatusCreated),
Timeout: time.Second * 30,
Interval: time.Second * 2,
})

By("access dataplane: path not matching regex should return 404")
s.RequestAssert(&scaffold.RequestAssert{
Method: "GET",
Path: "/status/ok",
Host: "httpbin.example",
Check: scaffold.WithExpectedStatus(http.StatusNotFound),
Timeout: time.Second * 30,
Interval: time.Second * 2,
})
})

It("HTTPRoute Method Match", func() {
By("create HTTPRoute")
s.ResourceApplied("HTTPRoute", "httpbin", fmt.Sprintf(methodRouteGETAndDELETEByAnything, s.Namespace()), 1)
Expand Down
Loading