Questions about the new expression router in Kong 3.0.0

Hello. I have many doubts with the new Kong expression router in version 3.0.0 (we need more information about it). I’ll ask two of them here:

1 - About && operator
We know that using regex in the expression is slower than using another operator:

http.path ^= “/api” is faster than http.path ~ “/api”

But, if I have this expression (filtering paths that starts with /api and have the version /api/v1/endpoint or /api/v3/endpoint).

Is this faster?

http.path ~ “/api/v[0-9]{1}/endpoint”

Or this with two conditions?

http.path ^= “/api” && http.path ~ “/api/v[0-9]{1}/endpoint”

From a programmer point of view, the last expression is faster because it will first check if the path starts with /api and if not then it is discarded and the second condition is not even checked (the RegExp). In the first expression the regex is always checked and it is a slower process.

Of course, we are assuming that the clients send requests that may start with /api or not, eg:

  • /api/v1/endpoint
  • /other/endpoint
  • /api/v3/endpoint

Does Kong expressions behave like that in AND (&&) expressions? If the first condition is not true, then the other ones does not even get evaluated?

2 - In a Route, how to strip part of the path only?

And another question. I create a Route for this path /api/v1/endpoint where the version can take multiple values (v1, v2, v3…).

Now I want to strip only “/api” from the path before passing it to the upstream, not strip all the path. What is the best way to do that?

Now I’m using a regex /api(/v[0-9]{1}/endpoint) and then I use the request-transform plugin replacing the uri with $(uri-capture[1]) to leave only /v1/endpoint. Maybe the example seems absurd but I do want to know the best way to do something like that.

Thank a lot.