Skip to content

Commit 070593c

Browse files
committed
Follow up #2354: Bump Ocelot.Testing to 25.0.0-beta.1
* Warning ASPDEPR008: 'IWebHostBuilder.Build()' is obsolete: 'IWebHost is obsolete. Use IHost instead. For more information, visit https://aka.ms/aspnet/deprecate/008
1 parent b8cc478 commit 070593c

File tree

52 files changed

+682
-1055
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+682
-1055
lines changed

src/Ocelot/Configuration/Creator/IUpstreamHeaderTemplatePatternCreator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Microsoft.AspNetCore.Http;
12
using Ocelot.Configuration.File;
23
using Ocelot.Values;
34

@@ -15,5 +16,5 @@ public interface IUpstreamHeaderTemplatePatternCreator
1516
/// <returns>An <see cref="IDictionary{TKey, TValue}"/> object where TKey is <see langword="string"/>, TValue is <see cref="UpstreamHeaderTemplate"/>.</returns>
1617
IDictionary<string, UpstreamHeaderTemplate> Create(IRouteUpstream route);
1718

18-
IDictionary<string, UpstreamHeaderTemplate> Create(IDictionary<string, string> upstreamHeaderTemplates, bool routeIsCaseSensitive);
19+
IDictionary<string, UpstreamHeaderTemplate> Create(IHeaderDictionary upstreamHeaderTemplates, bool routeIsCaseSensitive);
1920
}

src/Ocelot/Configuration/Creator/UpstreamHeaderTemplatePatternCreator.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Microsoft.AspNetCore.Http;
12
using Ocelot.Configuration.File;
23
using Ocelot.Infrastructure;
34
using Ocelot.Values;
@@ -13,10 +14,20 @@ public partial class UpstreamHeaderTemplatePatternCreator : IUpstreamHeaderTempl
1314
[GeneratedRegex(@"(\{header:.*?\})", RegexOptions.IgnoreCase | RegexOptions.Singleline, RegexGlobal.DefaultMatchTimeoutMilliseconds, "en-US")]
1415
private static partial Regex RegexPlaceholders();
1516

16-
public IDictionary<string, UpstreamHeaderTemplate> Create(IDictionary<string, string> upstreamHeaderTemplates, bool routeIsCaseSensitive)
17+
public IDictionary<string, UpstreamHeaderTemplate> Create(IRouteUpstream route)
1718
{
18-
var result = new Dictionary<string, UpstreamHeaderTemplate>();
19+
return Create(route.UpstreamHeaderTemplates, route.RouteIsCaseSensitive);
20+
}
21+
22+
public IDictionary<string, UpstreamHeaderTemplate> Create(IHeaderDictionary upstreamHeaderTemplates, bool routeIsCaseSensitive)
23+
{
24+
var headers = upstreamHeaderTemplates.ToDictionary(h => h.Key, h => h.Value.ToString()); // TODO Review usage
25+
return Create(headers, routeIsCaseSensitive);
26+
}
1927

28+
protected virtual IDictionary<string, UpstreamHeaderTemplate> Create(IDictionary<string, string> upstreamHeaderTemplates, bool routeIsCaseSensitive)
29+
{
30+
var result = new Dictionary<string, UpstreamHeaderTemplate>();
2031
foreach (var headerTemplate in upstreamHeaderTemplates)
2132
{
2233
var headerTemplateValue = headerTemplate.Value;
@@ -27,9 +38,9 @@ public IDictionary<string, UpstreamHeaderTemplate> Create(IDictionary<string, st
2738
var placeholders = matches.Select(m => m.Groups[1].Value).ToArray();
2839
for (int i = 0; i < placeholders.Length; i++)
2940
{
30-
var indexOfPlaceholder = headerTemplateValue.IndexOf(placeholders[i]);
31-
var placeholderName = placeholders[i][8..^1]; // remove "{header:" and "}"
32-
headerTemplateValue = headerTemplateValue.Replace(placeholders[i], $"(?<{placeholderName}>.+)");
41+
var placeholder = placeholders[i];
42+
var placeholderName = placeholder[8..^1]; // remove "{header:" and "}"
43+
headerTemplateValue = headerTemplateValue.Replace(placeholder, $"(?<{placeholderName}>.+)");
3344
}
3445
}
3546

@@ -42,7 +53,4 @@ public IDictionary<string, UpstreamHeaderTemplate> Create(IDictionary<string, st
4253

4354
return result;
4455
}
45-
46-
public IDictionary<string, UpstreamHeaderTemplate> Create(IRouteUpstream route)
47-
=> Create(route.UpstreamHeaderTemplates, route.RouteIsCaseSensitive);
4856
}

src/Ocelot/DownstreamRouteFinder/Finder/DiscoveryDownstreamRouteFinder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Ocelot.Configuration;
1+
using Microsoft.AspNetCore.Http;
2+
using Ocelot.Configuration;
23
using Ocelot.Configuration.Builder;
34
using Ocelot.Configuration.Creator;
45
using Ocelot.DownstreamRouteFinder.UrlMatcher;
@@ -28,7 +29,7 @@ public DiscoveryDownstreamRouteFinder(
2829
}
2930

3031
public Response<DownstreamRouteHolder> Get(string upstreamUrlPath, string upstreamQueryString, string upstreamHttpMethod,
31-
IInternalConfiguration configuration, string upstreamHost, IDictionary<string, string> upstreamHeaders)
32+
IInternalConfiguration configuration, string upstreamHost, IHeaderDictionary upstreamHeaders)
3233
{
3334
var serviceName = GetServiceName(upstreamUrlPath, out var serviceNamespace);
3435
var downstreamPath = GetDownstreamPath(upstreamUrlPath);

src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Ocelot.Configuration;
1+
using Microsoft.AspNetCore.Http;
2+
using Ocelot.Configuration;
23
using Ocelot.DownstreamRouteFinder.HeaderMatcher;
34
using Ocelot.DownstreamRouteFinder.UrlMatcher;
45
using Ocelot.Responses;
@@ -25,7 +26,7 @@ public DownstreamRouteFinder(
2526
}
2627

2728
public Response<DownstreamRouteHolder> Get(string upstreamUrlPath, string upstreamQueryString, string httpMethod,
28-
IInternalConfiguration configuration, string upstreamHost, IDictionary<string, string> upstreamHeaders)
29+
IInternalConfiguration configuration, string upstreamHost, IHeaderDictionary upstreamHeaders)
2930
{
3031
var downstreamRoutes = new List<DownstreamRouteHolder>();
3132

@@ -61,7 +62,7 @@ private static bool RouteIsApplicableToThisRequest(Route route, string httpMetho
6162
(string.IsNullOrEmpty(route.UpstreamHost) || route.UpstreamHost == upstreamHost);
6263
}
6364

64-
private DownstreamRouteHolder GetPlaceholderNamesAndValues(string path, string query, Route route, IDictionary<string, string> upstreamHeaders)
65+
private DownstreamRouteHolder GetPlaceholderNamesAndValues(string path, string query, Route route, IHeaderDictionary upstreamHeaders)
6566
{
6667
var templatePlaceholderNameAndValues = _pathPlaceholderFinder
6768
.Find(path, query, route.UpstreamTemplatePattern.OriginalValue)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using Ocelot.Configuration;
1+
using Microsoft.AspNetCore.Http;
2+
using Ocelot.Configuration;
23
using Ocelot.Responses;
34

45
namespace Ocelot.DownstreamRouteFinder.Finder;
56

67
public interface IDownstreamRouteProvider
78
{
89
Response<DownstreamRouteHolder> Get(string upstreamUrlPath, string upstreamQueryString, string upstreamHttpMethod,
9-
IInternalConfiguration configuration, string upstreamHost, IDictionary<string, string> upstreamHeaders);
10+
IInternalConfiguration configuration, string upstreamHost, IHeaderDictionary upstreamHeaders);
1011
}

src/Ocelot/DownstreamRouteFinder/HeaderMatcher/HeaderPlaceholderNameAndValueFinder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using Ocelot.DownstreamRouteFinder.UrlMatcher;
1+
using Microsoft.AspNetCore.Http;
2+
using Ocelot.DownstreamRouteFinder.UrlMatcher;
23
using Ocelot.Values;
34

45
namespace Ocelot.DownstreamRouteFinder.HeaderMatcher;
56

67
public class HeaderPlaceholderNameAndValueFinder : IHeaderPlaceholderNameAndValueFinder
78
{
8-
public IList<PlaceholderNameAndValue> Find(IDictionary<string, string> upstreamHeaders, IDictionary<string, UpstreamHeaderTemplate> templateHeaders)
9+
public IList<PlaceholderNameAndValue> Find(IHeaderDictionary upstreamHeaders, IDictionary<string, UpstreamHeaderTemplate> templateHeaders)
910
{
1011
var result = new List<PlaceholderNameAndValue>();
1112
foreach (var templateHeader in templateHeaders)
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
using Ocelot.Values;
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.Extensions.Primitives;
3+
using Ocelot.Values;
24

35
namespace Ocelot.DownstreamRouteFinder.HeaderMatcher;
46

57
public class HeadersToHeaderTemplatesMatcher : IHeadersToHeaderTemplatesMatcher
68
{
7-
public bool Match(IDictionary<string, string> upstreamHeaders, IDictionary<string, UpstreamHeaderTemplate> routeHeaders) =>
8-
routeHeaders == null ||
9-
upstreamHeaders != null
10-
&& routeHeaders.All(h => upstreamHeaders.ContainsKey(h.Key) && routeHeaders[h.Key].Pattern.IsMatch(upstreamHeaders[h.Key]));
9+
public bool Match(IHeaderDictionary upstreamHeaders, IDictionary<string, UpstreamHeaderTemplate> routeHeaders)
10+
{
11+
bool IsMatching(KeyValuePair<string, UpstreamHeaderTemplate> h)
12+
{
13+
return upstreamHeaders.TryGetValue(h.Key, out StringValues header)
14+
&& routeHeaders[h.Key].Pattern.IsMatch(header);
15+
}
16+
return routeHeaders == null || upstreamHeaders != null && routeHeaders.All(IsMatching);
17+
}
1118
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Ocelot.DownstreamRouteFinder.UrlMatcher;
1+
using Microsoft.AspNetCore.Http;
2+
using Ocelot.DownstreamRouteFinder.UrlMatcher;
23
using Ocelot.Values;
34

45
namespace Ocelot.DownstreamRouteFinder.HeaderMatcher;
@@ -8,5 +9,5 @@ namespace Ocelot.DownstreamRouteFinder.HeaderMatcher;
89
/// </summary>
910
public interface IHeaderPlaceholderNameAndValueFinder
1011
{
11-
IList<PlaceholderNameAndValue> Find(IDictionary<string, string> upstreamHeaders, IDictionary<string, UpstreamHeaderTemplate> templateHeaders);
12+
IList<PlaceholderNameAndValue> Find(IHeaderDictionary upstreamHeaders, IDictionary<string, UpstreamHeaderTemplate> templateHeaders);
1213
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Ocelot.Values;
1+
using Microsoft.AspNetCore.Http;
2+
using Ocelot.Values;
23

34
namespace Ocelot.DownstreamRouteFinder.HeaderMatcher;
45

@@ -7,5 +8,5 @@ namespace Ocelot.DownstreamRouteFinder.HeaderMatcher;
78
/// </summary>
89
public interface IHeadersToHeaderTemplatesMatcher
910
{
10-
bool Match(IDictionary<string, string> upstreamHeaders, IDictionary<string, UpstreamHeaderTemplate> routeHeaders);
11+
bool Match(IHeaderDictionary upstreamHeaders, IDictionary<string, UpstreamHeaderTemplate> routeHeaders);
1112
}

src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public async Task Invoke(HttpContext httpContext)
2929
var upstreamHost = hostHeader.Contains(':')
3030
? hostHeader.Split(':')[0]
3131
: hostHeader;
32-
var upstreamHeaders = httpContext.Request.Headers
33-
.ToDictionary(h => h.Key, h => string.Join(';', (IList<string>)h.Value));
32+
var upstreamHeaders = httpContext.Request.Headers;
3433

3534
Logger.LogDebug(() => $"Upstream URL path: {upstreamUrlPath}");
3635

0 commit comments

Comments
 (0)