Route order not respected for "*" host
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
---
**Issue moved from microsoft/reverse-proxy#1530**
- Please respond to @luk355.
---
_From @luk355 on Tuesday, January 25, 2022 2:49:39 PM_
### Describe the bug
Route order is not respected for routes with "*" wildcard in the hosts - see "To Reproduce" section.
### To Reproduce
Setup proxy with following configuration:
```csharp
public class EsProxyConfig : IProxyConfig
{
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
public EsProxyConfig()
{
ChangeToken = new CancellationChangeToken(_cts.Token);
}
public IReadOnlyList Routes => new List()
{
new RouteConfig()
{
ClusterId = "httpbin",
RouteId = "httpbin",
Match = new RouteMatch() {
Path = "{**catch-all}",
Hosts = new[] { "*" }
},
Order= 1
},
new RouteConfig()
{
ClusterId = "github",
RouteId = "github",
Match = new RouteMatch() {
Path = "{**catch-all}",
Hosts = new[] { "foo-localhost" }
},
Order= 10
}
};
public IReadOnlyList Clusters => new List() {
new ClusterConfig()
{
ClusterId = "httpbin",
Destinations = new Dictionary(StringComparer.OrdinalIgnoreCase)
{
{ "destination", new DestinationConfig() { Address = "https://httpbin.org" } },
}
},
new ClusterConfig()
{
ClusterId = "github",
Destinations = new Dictionary(StringComparer.OrdinalIgnoreCase)
{
{ "destination", new DestinationConfig() { Address = "https://github.com" } },
},
}
};
public IChangeToken ChangeToken { get; }
}
```
The httpbin route has "*" wildcard provided in the hosts and has lower order - therefore all requests to the proxy should be routed to httpbin. Given the proxy running on localhost, see the requests toghether with expected/and the actual route (wrong routing highlighted as bold):
| Request | Expected route | The actual route |
| ------------------------------------------------- | ---------------- | ------------------ |
| curl http://localhost | httpbin | httpbin |
| curl -H "Host:foo-localhost" http://localhost | httpbin | **github** |
To get the routing work as expected, hosts configuration from httpbin route can be ommited as shown below.
```csharp
new RouteConfig()
{
ClusterId = "httpbin",
RouteId = "httpbin",
Match = new RouteMatch() {
Path = "{**catch-all}",
// REMOVE HOSTS CONFIGURATION
// Hosts = new[] { "*" }
},
Order= 1
},
```
### Further technical details
- .NET 6
- YARP.ReverseProxy v1.0.0
- Platform: Windows
Contributor guide
Assessment
This issue has not been assessed yet.