Skip to content

Commit

Permalink
Couple of changes for the second round of PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrclayman authored and raman-m committed Feb 17, 2024
1 parent 1bf0517 commit 5f56f96
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,15 @@ private static bool AreDuplicates(IDictionary<string, ICollection<string>> first
{
return true;
}


// if either of the two header collections is empty while the other is not, it's obvious that they can never be duplicate
if (first.Any() ^ second.Any())
{
return false;
}

var firstKeySet = first.Keys
.Select(k => k.ToUpperInvariant())
.ToArray();
var secondKeySet = second.Keys
.Select(k => k.ToUpperInvariant())
.ToArray();
var firstKeySet = first.Keys.Select(k => k.ToUpperInvariant());
var secondKeySet = second.Keys.Select(k => k.ToUpperInvariant());
if (!firstKeySet.Intersect(secondKeySet).Any())
{
return false;
Expand Down
10 changes: 5 additions & 5 deletions src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public Response<DownstreamRouteHolder> Get(
private static bool RouteIsApplicableToThisRequest(Route route, string httpMethod, string upstreamHost, IHeaderDictionary requestHeaders)
=> (route.UpstreamHttpMethod.Count == 0 || RouteHasHttpMethod(route, httpMethod)) &&
(string.IsNullOrEmpty(route.UpstreamHost) || route.UpstreamHost == upstreamHost) &&
(route.UpstreamHeaderRoutingOptions?.Enabled() != true || RouteHasRequiredUpstreamHeaders(route, requestHeaders));
(route.UpstreamHeaderRoutingOptions?.Enabled() != true || RequiredUpstreamHeadersArePresent(route.UpstreamHeaderRoutingOptions, requestHeaders));

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

private static bool RouteHasRequiredUpstreamHeaders(Route route, IHeaderDictionary requestHeaders) =>
route.UpstreamHeaderRoutingOptions.Mode == UpstreamHeaderRoutingTriggerMode.Any
? route.UpstreamHeaderRoutingOptions.Headers.HasAnyOf(requestHeaders)
: route.UpstreamHeaderRoutingOptions.Headers.HasAllOf(requestHeaders);
private static bool RequiredUpstreamHeadersArePresent(UpstreamHeaderRoutingOptions options, IHeaderDictionary requestHeaders) =>
options.Mode == UpstreamHeaderRoutingTriggerMode.Any
? options.Headers.HasAnyOf(requestHeaders)
: options.Headers.HasAllOf(requestHeaders);

private DownstreamRouteHolder GetPlaceholderNamesAndValues(string path, string query, Route route)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ namespace Ocelot.UnitTests.Configuration;
public class UpstreamHeaderRoutingOptionsCreatorTests
{
private FileUpstreamHeaderRoutingOptions _fileUpstreamHeaderRoutingOptions;
private IUpstreamHeaderRoutingOptionsCreator _creator;
private readonly IUpstreamHeaderRoutingOptionsCreator _creator = new UpstreamHeaderRoutingOptionsCreator();
private UpstreamHeaderRoutingOptions _upstreamHeaderRoutingOptions;

public UpstreamHeaderRoutingOptionsCreatorTests()
{
_creator = new UpstreamHeaderRoutingOptionsCreator();
}

[Fact]
public void should_create_upstream_routing_header_options()
{
Expand Down

0 comments on commit 5f56f96

Please sign in to comment.