Skip to content

Commit eb9db94

Browse files
committed
Couple of changes for the second round of PR feedback.
1 parent 44df120 commit eb9db94

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,15 @@ private static bool AreDuplicates(IDictionary<string, ICollection<string>> first
178178
{
179179
return true;
180180
}
181-
181+
182182
// if either of the two header collections is empty while the other is not, it's obvious that they can never be duplicate
183183
if (first.Any() ^ second.Any())
184184
{
185185
return false;
186186
}
187187

188-
var firstKeySet = first.Keys
189-
.Select(k => k.ToUpperInvariant())
190-
.ToArray();
191-
var secondKeySet = second.Keys
192-
.Select(k => k.ToUpperInvariant())
193-
.ToArray();
188+
var firstKeySet = first.Keys.Select(k => k.ToUpperInvariant());
189+
var secondKeySet = second.Keys.Select(k => k.ToUpperInvariant());
194190
if (!firstKeySet.Intersect(secondKeySet).Any())
195191
{
196192
return false;

src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Net.Http;
4+
using System.Net.Http;
55
using Microsoft.AspNetCore.Http;
66
using Ocelot.Configuration;
77
using Ocelot.DownstreamRouteFinder.UrlMatcher;
@@ -58,15 +58,15 @@ public Response<DownstreamRouteHolder> Get(
5858
private static bool RouteIsApplicableToThisRequest(Route route, string httpMethod, string upstreamHost, IHeaderDictionary requestHeaders)
5959
=> (route.UpstreamHttpMethod.Count == 0 || RouteHasHttpMethod(route, httpMethod)) &&
6060
(string.IsNullOrEmpty(route.UpstreamHost) || route.UpstreamHost == upstreamHost) &&
61-
(route.UpstreamHeaderRoutingOptions?.Enabled() != true || RouteHasRequiredUpstreamHeaders(route, requestHeaders));
61+
(route.UpstreamHeaderRoutingOptions?.Enabled() != true || RequiredUpstreamHeadersArePresent(route.UpstreamHeaderRoutingOptions, requestHeaders));
6262

6363
private static bool RouteHasHttpMethod(Route route, string httpMethod) =>
6464
route.UpstreamHttpMethod.Contains(new HttpMethod(httpMethod));
6565

66-
private static bool RouteHasRequiredUpstreamHeaders(Route route, IHeaderDictionary requestHeaders) =>
67-
route.UpstreamHeaderRoutingOptions.Mode == UpstreamHeaderRoutingTriggerMode.Any
68-
? route.UpstreamHeaderRoutingOptions.Headers.HasAnyOf(requestHeaders)
69-
: route.UpstreamHeaderRoutingOptions.Headers.HasAllOf(requestHeaders);
66+
private static bool RequiredUpstreamHeadersArePresent(UpstreamHeaderRoutingOptions options, IHeaderDictionary requestHeaders) =>
67+
options.Mode == UpstreamHeaderRoutingTriggerMode.Any
68+
? options.Headers.HasAnyOf(requestHeaders)
69+
: options.Headers.HasAllOf(requestHeaders);
7070

7171
private DownstreamRouteHolder GetPlaceholderNamesAndValues(string path, string query, Route route)
7272
{

test/Ocelot.UnitTests/Configuration/UpstreamHeaderRoutingOptionsCreatorTests.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ namespace Ocelot.UnitTests.Configuration;
1212
public class UpstreamHeaderRoutingOptionsCreatorTests
1313
{
1414
private FileUpstreamHeaderRoutingOptions _fileUpstreamHeaderRoutingOptions;
15-
private IUpstreamHeaderRoutingOptionsCreator _creator;
15+
private readonly IUpstreamHeaderRoutingOptionsCreator _creator = new UpstreamHeaderRoutingOptionsCreator();
1616
private UpstreamHeaderRoutingOptions _upstreamHeaderRoutingOptions;
1717

18-
public UpstreamHeaderRoutingOptionsCreatorTests()
19-
{
20-
_creator = new UpstreamHeaderRoutingOptionsCreator();
21-
}
22-
2318
[Fact]
2419
public void should_create_upstream_routing_header_options()
2520
{

0 commit comments

Comments
 (0)