Hello!
First of all, thank you for your service.
I am writing this topic for inquiry.
In version 5.3.2 of tyk-gateway, API applied based on domain and listen path is not what I expected. It seems there are some unknown criteria which prioritizing through APIs.
I understand that it is working by the code I attach below.
// tyk-5.3.2/gateway/api_loader.go/(gw *Gateway) loadApps
// sort by listen path from longer to shorter, so that /foo
// doesn't break /foo-bar
sort.Slice(specs, func(i, j int) bool {
if specs[i].Domain != specs[j].Domain {
return len(specs[i].Domain) > len(specs[j].Domain)
}
return len(specs[i].Proxy.ListenPath) > len(specs[j].Proxy.ListenPath)
})
It seems the code of if-condition doesn’t work properly.
I think there is an issue for different domain with same length, it doesn’t follow the rule of listen path.
[Expected sorting conditions]
- If a length of the domain set in API definition is longer, the priority is higher
- If there are same domains, the priority is higher for the length of listen path
[Issue]
- Different domain names, but same length, are not sorted in listen path length order
[Example]
[test-a.json API Definition]
domain: test-domain-a.com
listesn path: /test/listen/path[test-b.json API Definition]
domain: test-domain-b.com
listesn path: /test/listen/path[test-c.json API Definition]
domain: test-domain-a.com
listesn path: /test/listen/path/a
By the sets I wrote above, a priority is randomly determined according to the API loading order because the length of the domain, (e.g. which are 17 characters,) is the only parameter passed to pdqsort_func(), also listen paths length.
Therefore, if I call https://test-domain-a.com/test/listen/path/a
, depends on the case, the rule would not follow test-c.json’s settings, but rather test-a.json’s.
Please share any idea to solve this issue.
Best regards,