Skip to content

Commit 5f56f96

Browse files
mrclaymanraman-m
authored andcommitted
Couple of changes for the second round of PR feedback.
1 parent 1bf0517 commit 5f56f96

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,15 @@ private static bool AreDuplicates(IDictionary<string, ICollection<string>> first
164164
{
165165
return true;
166166
}
167-
167+
168168
// if either of the two header collections is empty while the other is not, it's obvious that they can never be duplicate
169169
if (first.Any() ^ second.Any())
170170
{
171171
return false;
172172
}
173173

174-
var firstKeySet = first.Keys
175-
.Select(k => k.ToUpperInvariant())
176-
.ToArray();
177-
var secondKeySet = second.Keys
178-
.Select(k => k.ToUpperInvariant())
179-
.ToArray();
174+
var firstKeySet = first.Keys.Select(k => k.ToUpperInvariant());
175+
var secondKeySet = second.Keys.Select(k => k.ToUpperInvariant());
180176
if (!firstKeySet.Intersect(secondKeySet).Any())
181177
{
182178
return false;

src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ public Response<DownstreamRouteHolder> Get(
5454
private static bool RouteIsApplicableToThisRequest(Route route, string httpMethod, string upstreamHost, IHeaderDictionary requestHeaders)
5555
=> (route.UpstreamHttpMethod.Count == 0 || RouteHasHttpMethod(route, httpMethod)) &&
5656
(string.IsNullOrEmpty(route.UpstreamHost) || route.UpstreamHost == upstreamHost) &&
57-
(route.UpstreamHeaderRoutingOptions?.Enabled() != true || RouteHasRequiredUpstreamHeaders(route, requestHeaders));
57+
(route.UpstreamHeaderRoutingOptions?.Enabled() != true || RequiredUpstreamHeadersArePresent(route.UpstreamHeaderRoutingOptions, requestHeaders));
5858

5959
private static bool RouteHasHttpMethod(Route route, string httpMethod) =>
6060
route.UpstreamHttpMethod.Contains(new HttpMethod(httpMethod));
6161

62-
private static bool RouteHasRequiredUpstreamHeaders(Route route, IHeaderDictionary requestHeaders) =>
63-
route.UpstreamHeaderRoutingOptions.Mode == UpstreamHeaderRoutingTriggerMode.Any
64-
? route.UpstreamHeaderRoutingOptions.Headers.HasAnyOf(requestHeaders)
65-
: route.UpstreamHeaderRoutingOptions.Headers.HasAllOf(requestHeaders);
62+
private static bool RequiredUpstreamHeadersArePresent(UpstreamHeaderRoutingOptions options, IHeaderDictionary requestHeaders) =>
63+
options.Mode == UpstreamHeaderRoutingTriggerMode.Any
64+
? options.Headers.HasAnyOf(requestHeaders)
65+
: options.Headers.HasAllOf(requestHeaders);
6666

6767
private DownstreamRouteHolder GetPlaceholderNamesAndValues(string path, string query, Route route)
6868
{

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)