Skip to content

Commit

Permalink
Add Query Parameter MatchPolicy, more Header matches (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksauce authored Oct 8, 2021
1 parent 34fa689 commit e74dade
Show file tree
Hide file tree
Showing 29 changed files with 1,684 additions and 20 deletions.
18 changes: 13 additions & 5 deletions docs/docfx/articles/config-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,22 @@ For additional fields see [ClusterConfig](xref:Yarp.ReverseProxy.Configuration.C
"Path": "/something/{**remainder}", // The path to match using ASP.NET syntax.
"Hosts" : [ "www.aaaaa.com", "www.bbbbb.com"], // The host names to match, unspecified is any
"Methods" : [ "GET", "PUT" ], // The HTTP methods that match, uspecified is all
"Headers" : [ // The headers to match, unspecified is any
"Headers": [ // The headers to match, unspecified is any
{
"Name" : "MyCustomHeader", // Name of the header
"Values" : ["value1", "value2", "another value"], // Matches are against any of these values
"Mode" : "ExactHeader", // or "HeaderPrefix", "Exists"
"IsCaseSensitive" : true
"Name": "MyCustomHeader", // Name of the header
"Values": [ "value1", "value2", "another value" ], // Matches are against any of these values
"Mode": "ExactHeader", // or "HeaderPrefix", "Exists" , "Contains", "NotContains"
"IsCaseSensitive": true
}
],
"QueryParameters": [ // The query parameters to match, unspecified is any
{
"Name": "MyQueryParameter", // Name of the query parameter
"Values": [ "value1", "value2", "another value" ], // Matches are against any of these values
"Mode": "Exact", // or "Prefix", "Exists" , "Contains", "NotContains"
"IsCaseSensitive": true
}
]
},
"MetaData" : { // List of key value pairs that can be used by custom extensions
"MyName" : "MyValue"
Expand Down
76 changes: 74 additions & 2 deletions docs/docfx/articles/header-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Proxy routes specified in [config](config-files.md) or via [code](config-provide

### Precedence

The default route match precedence order is 1) path, 2) method, 3) host, 4) headers. That means a route which specifies methods and no headers will match before a route which specifies headers and no methods. This can be overridden by setting the `Order` property on a route.
The default route match precedence order is 1) path, 2) method, 3) host, 4) headers 5) query parameters. That means a route which specifies methods and no headers will match before a route which specifies headers and no methods. This can be overridden by setting the `Order` property on a route.

## Configuration

Expand Down Expand Up @@ -74,6 +74,40 @@ Configuration:
}
]
}
},
"route5" : {
"ClusterId": "cluster1",
"Match": {
"Path": "{**catch-all}",
"Headers": [
{
"Name": "header5",
"Values": [ "value1", "value2" ],
"Mode": "Contains"
},
{
"Name": "header6",
"Mode": "Exists"
}
]
}
},
"route6" : {
"ClusterId": "cluster1",
"Match": {
"Path": "{**catch-all}",
"Headers": [
{
"Name": "header6",
"Values": [ "value1", "value2" ],
"Mode": "NotContains"
},
{
"Name": "header7",
"Mode": "Exists"
}
]
}
}
}
```
Expand Down Expand Up @@ -157,6 +191,42 @@ var routes = new[]
}
}
}
},
new RouteConfig()
{
RouteId = "route5",
ClusterId = "cluster1",
Match = new RouteMatch
{
Path = "{**catch-all}",
Headers = new[]
{
new RouteHeader()
{
Name = "Header5",
Values = new[] { "value1", "value2" },
Mode = HeaderMatchMode.Contains
}
}
}
},
new RouteConfig()
{
RouteId = "route6",
ClusterId = "cluster1",
Match = new RouteMatch
{
Path = "{**catch-all}",
Headers = new[]
{
new RouteHeader()
{
Name = "Header6",
Values = new[] { "value1", "value2" },
Mode = HeaderMatchMode.NotContains
}
}
}
}
};
```
Expand All @@ -171,14 +241,16 @@ The header name to check for on the request. A non-empty value is required. This

### Values

A list of possible values to search for. The header must match at least one of these values according to the specified `Mode`. At least one value is required unless `Mode` is set to `Exists`.
A list of possible values to search for. The header must match at least one of these values according to the specified `Mode` except for the 'NotContains'. At least one value is required unless `Mode` is set to `Exists`.

### Mode

[HeaderMatchMode](xref:Yarp.ReverseProxy.Configuration.HeaderMatchMode) specifies how to match the value(s) against the request header. The default is `ExactHeader`.
- ExactHeader - The header must match in its entirety, subject to the value of `IsCaseSensitive`. Only single headers are supported. If there are multiple headers with the same name then the match fails.
- HeaderPrefix - The header must match by prefix, subject to the value of `IsCaseSensitive`. Only single headers are supported. If there are multiple headers with the same name then the match fails.
- Exists - The header must exist and contain any non-empty value.
- Contains - The header must contain the value for a match, subject to the value of `IsCaseSensitive`. Only single headers are supported. If there are multiple headers with the same name then the match fails.
- NotContains - The header must not contain any of the match values, subject to the value of `IsCaseSensitive`. Only single headers are supported. If there are multiple headers with the same name then the match fails.

### IsCaseSensitive

Expand Down
Loading

0 comments on commit e74dade

Please sign in to comment.