Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update notExists to true when value is empty #2412

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading