Skip to content

Commit

Permalink
Update notExists to true when value is empty (#2412)
Browse files Browse the repository at this point in the history
* Update notExists to true when value is empty

* Simplify the condition further

---------

Co-authored-by: Casey Sun <caseysun@microsoft.com>
Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
  • Loading branch information
3 people authored Mar 5, 2024
1 parent 800339e commit e672f15
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ReverseProxy/Routing/HeaderMatcherPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates)

foreach (var matcher in matchers)
{
var headerExists = headers.TryGetValue(matcher.Name, out var requestHeaderValues);
headers.TryGetValue(matcher.Name, out var requestHeaderValues);
var valueIsEmpty = StringValues.IsNullOrEmpty(requestHeaderValues);

var matched = matcher.Mode switch
{
HeaderMatchMode.Exists => !valueIsEmpty,
HeaderMatchMode.NotExists => !headerExists,
HeaderMatchMode.NotExists => valueIsEmpty,
HeaderMatchMode.ExactHeader => !valueIsEmpty && TryMatchExactOrPrefix(matcher, requestHeaderValues),
HeaderMatchMode.HeaderPrefix => !valueIsEmpty && TryMatchExactOrPrefix(matcher, requestHeaderValues),
HeaderMatchMode.Contains => !valueIsEmpty && TryMatchContainsOrNotContains(matcher, requestHeaderValues),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void AppliesToEndpoints_NoMetadata_DoesNotApply()
[InlineData("", HeaderMatchMode.Exists, false)]
[InlineData("abc", HeaderMatchMode.Exists, true)]
[InlineData(null, HeaderMatchMode.NotExists, true)]
[InlineData("", HeaderMatchMode.NotExists, false)]
[InlineData("", HeaderMatchMode.NotExists, true)]
[InlineData("abc", HeaderMatchMode.NotExists, false)]
public async Task ApplyAsync_MatchingScenarios_AnyHeaderValue(string incomingHeaderValue, HeaderMatchMode mode, bool shouldMatch)
{
Expand Down

0 comments on commit e672f15

Please sign in to comment.