Browse Source

converted into linq language feature (#835)

* converted into linq language feature

* removed MemoryExtensions.Equals

* removed MemoryExtensions.Equals

* removed insted ifs

* applied dotnet format

* removed unused else if into if

* Update IngressHostMatcherPolicy.cs

Co-authored-by: Justin Kotalik <jukotali@microsoft.com>
pull/874/head
Marvin Huber 6 years ago
committed by GitHub
parent
commit
40820c58c2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 56
      src/Microsoft.Tye.Hosting/Infrastructure/IngressHostMatcherPolicy.cs

56
src/Microsoft.Tye.Hosting/Infrastructure/IngressHostMatcherPolicy.cs

@ -28,17 +28,8 @@ namespace Microsoft.AspNetCore.Routing.Matching
return false; return false;
} }
foreach (var host in hosts) return hosts.Select(CreateEdgeKey)
{ .Any(key => !key.MatchesAll);
// Don't run policy on endpoints that match everything
var key = CreateEdgeKey(host);
if (!key.MatchesAll)
{
return true;
}
}
return false;
}); });
} }
@ -83,7 +74,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
host = host.Slice(0, pivot); host = host.Slice(0, pivot);
} }
if (host == null || MemoryExtensions.Equals(host, WildcardHost, StringComparison.OrdinalIgnoreCase)) if (host == null || host.Equals(WildcardHost, StringComparison.OrdinalIgnoreCase))
{ {
// Can match any host // Can match any host
} }
@ -105,7 +96,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
continue; continue;
} }
if (MemoryExtensions.Equals(port, WildcardHost, StringComparison.OrdinalIgnoreCase)) if (port.Equals(WildcardHost, StringComparison.OrdinalIgnoreCase))
{ {
// Port is a wildcard, we allow any port. // Port is a wildcard, we allow any port.
} }
@ -143,19 +134,23 @@ namespace Microsoft.AspNetCore.Routing.Matching
return new EdgeKey(hostParts[0], null); return new EdgeKey(hostParts[0], null);
} }
} }
if (hostParts.Length == 2)
if (hostParts.Length != 2)
{ {
if (!string.IsNullOrEmpty(hostParts[0])) throw new InvalidOperationException($"Could not parse host: {host}");
{ }
if (int.TryParse(hostParts[1], out var port)) if (string.IsNullOrEmpty(hostParts[0]))
{ {
return new EdgeKey(hostParts[0], port); throw new InvalidOperationException($"Could not parse host: {host}");
} }
else if (string.Equals(hostParts[1], WildcardHost, StringComparison.Ordinal)) if (int.TryParse(hostParts[1], out var port))
{ {
return new EdgeKey(hostParts[0], null); return new EdgeKey(hostParts[0], port);
} }
}
if (string.Equals(hostParts[1], WildcardHost, StringComparison.Ordinal))
{
return new EdgeKey(hostParts[0], null);
} }
throw new InvalidOperationException($"Could not parse host: {host}"); throw new InvalidOperationException($"Could not parse host: {host}");
@ -168,18 +163,17 @@ namespace Microsoft.AspNetCore.Routing.Matching
{ {
return (hostString.Host, hostString.Port); return (hostString.Host, hostString.Port);
} }
else if (string.Equals("https", httpContext.Request.Scheme, StringComparison.OrdinalIgnoreCase))
if (string.Equals("https", httpContext.Request.Scheme, StringComparison.OrdinalIgnoreCase))
{ {
return (hostString.Host, 443); return (hostString.Host, 443);
} }
else if (string.Equals("http", httpContext.Request.Scheme, StringComparison.OrdinalIgnoreCase))
if (string.Equals("http", httpContext.Request.Scheme, StringComparison.OrdinalIgnoreCase))
{ {
return (hostString.Host, 80); return (hostString.Host, 80);
} }
else return (hostString.Host, null);
{
return (hostString.Host, null);
}
} }
private readonly struct EdgeKey private readonly struct EdgeKey

Loading…
Cancel
Save