For each incoming request, Kong Gateway must determine which
service gets to handle it based on the routes that are defined. With
release 3.0, Kong Gateway introduced a router that can be
running in two modes: the traditional_compat
mode, which is
configured like prior releases, and the expressions
mode which uses
a new configuration scheme. We recommend that new deployments use
the expressions router as it is more powerful and expressive.
The default mode of the router is traditional_compat
and the
following sections describe how it operates. traditional_compat
mode is designed to behave like the router in versions before
Kong Gateway 3.x. For a description of the expressions
mode, see
How to Configure Routes using Expressions.
In general, the router orders all defined routes by their priority and uses the highest priority matching route to handle a request. If there are multiple matching routes with the same priority, it is not defined which of the matching routes will be used and Kong Gateway will use either of them according to how its internal data structures are organized.
If a route contains prefix or regular expression paths, the priority of the route will be calculated separately for each of the paths and requests will be routed accordingly.
In traditional_compat
mode, the priority of a route is determined as
follows, by the order of descending significance:
- Priority points
- Wildcard hosts
- Header count
- Regular expressions and prefix paths
Priority points
For the presence of each of a route’s methods
, host
, headers
,
and snis
, a “priority point” will be added to the route. The number
of “priority points” determines the overall order in which the routes
will be considered. Routes with a higher “priority point” values will
be considered before those with lower values. This means that if one
route has methods
defined, and second one has methods
and
headers
defined, the second one will be considered before the first
one.
Wildcard hosts
Among the routes with the same “priority point” value, those that have any wildcard host specification will be considered after routes that don’t have any wildcard host (or no host) specified.
Header count
The resulting groups are sorted so the routes with a higher number of specified headers have higher priority than those with a lower number of headers.