From f4e9b53cc8c295bd4224ccfd16c899076609c8e3 Mon Sep 17 00:00:00 2001 From: Howard Richards Date: Fri, 12 Nov 2021 08:57:41 +0000 Subject: [PATCH 1/3] Upgraded Yarp to v1.0 --- .../ReCode.Cocoon.Proxy/Proxy/CocoonProxy.cs | 18 +++++++++--------- .../Proxy/CocoonProxyServicesExtensions.cs | 4 ++-- .../Proxy/RedirectTransformer.cs | 6 +++--- .../ReCode.Cocoon.Proxy.csproj | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/main/src/ReCode.Cocoon.Proxy/Proxy/CocoonProxy.cs b/main/src/ReCode.Cocoon.Proxy/Proxy/CocoonProxy.cs index 42a160e..d57d77d 100644 --- a/main/src/ReCode.Cocoon.Proxy/Proxy/CocoonProxy.cs +++ b/main/src/ReCode.Cocoon.Proxy/Proxy/CocoonProxy.cs @@ -7,23 +7,23 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -using Yarp.ReverseProxy.Service.Proxy; +using Yarp.ReverseProxy.Forwarder; namespace ReCode.Cocoon.Proxy.Proxy { public class CocoonProxy { private static readonly ActivitySource Source = new("ReCode.Cocoon.Proxy"); - private readonly IHttpProxy _httpProxy; + private readonly IHttpForwarder _httpProxy; private readonly HashSet _backendUrls; private readonly HttpMessageInvoker _httpClient; private readonly RedirectTransformer _transformer; - private readonly RequestProxyOptions _requestOptions; + private readonly ForwarderRequestConfig _requestOptions; private readonly string _destinationPrefix; - public CocoonProxy(IConfiguration configuration, ILogger logger, IHttpProxy httpProxy, CocoonProxyOptions? proxyOptions) + public CocoonProxy(IConfiguration configuration, ILogger logger, IHttpForwarder httpForwarder, CocoonProxyOptions? proxyOptions) { - _httpProxy = httpProxy; + _httpProxy = httpForwarder; _destinationPrefix = configuration .GetValue("Cocoon:Proxy:DestinationPrefix"); @@ -37,7 +37,7 @@ public CocoonProxy(IConfiguration configuration, ILogger logger, IH throw new InvalidOperationException("Invalid DestinationPrefix"); } - logger.LogInformation($"Cocoon Proxy backend: {destinationPrefixUri}"); + logger?.LogInformation($"Cocoon Proxy backend: {destinationPrefixUri}"); _backendUrls = CocoonProxyExclusions.CreateExclusionSet(configuration); @@ -62,9 +62,9 @@ public CocoonProxy(IConfiguration configuration, ILogger logger, IH { timeout = TimeSpan.FromSeconds(30); } - _requestOptions = new RequestProxyOptions + _requestOptions = new ForwarderRequestConfig { - Timeout = timeout + ActivityTimeout = timeout }; } @@ -79,7 +79,7 @@ public async Task ProxyAsync(HttpContext httpContext) using var activity = Source.StartActivity("Proxy"); activity?.SetTag("path", httpContext.Request.Path.ToString()); - await _httpProxy.ProxyAsync(httpContext, _destinationPrefix, _httpClient, _requestOptions, _transformer); + await _httpProxy.SendAsync(httpContext, _destinationPrefix, _httpClient, _requestOptions, _transformer); } } } \ No newline at end of file diff --git a/main/src/ReCode.Cocoon.Proxy/Proxy/CocoonProxyServicesExtensions.cs b/main/src/ReCode.Cocoon.Proxy/Proxy/CocoonProxyServicesExtensions.cs index ca94bea..cf23526 100644 --- a/main/src/ReCode.Cocoon.Proxy/Proxy/CocoonProxyServicesExtensions.cs +++ b/main/src/ReCode.Cocoon.Proxy/Proxy/CocoonProxyServicesExtensions.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using ReCode.Cocoon.Proxy.Proxy; -using Yarp.ReverseProxy.Service.Proxy; +using Yarp.ReverseProxy.Forwarder; // ReSharper disable once CheckNamespace namespace Microsoft.Extensions.DependencyInjection @@ -18,7 +18,7 @@ public static IReverseProxyBuilder AddCocoonProxy(this IServiceCollection servic services.AddSingleton(provider => new CocoonProxy( configuration, provider.GetService>(), - provider.GetService(), cocoonProxyOptions)); + provider.GetService(), cocoonProxyOptions)); return ReverseProxyBuilder(services, configuration); } diff --git a/main/src/ReCode.Cocoon.Proxy/Proxy/RedirectTransformer.cs b/main/src/ReCode.Cocoon.Proxy/Proxy/RedirectTransformer.cs index d4db481..ecbb932 100644 --- a/main/src/ReCode.Cocoon.Proxy/Proxy/RedirectTransformer.cs +++ b/main/src/ReCode.Cocoon.Proxy/Proxy/RedirectTransformer.cs @@ -2,7 +2,7 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Yarp.ReverseProxy.Service.Proxy; +using Yarp.ReverseProxy.Forwarder; namespace ReCode.Cocoon.Proxy.Proxy { @@ -15,7 +15,7 @@ public RedirectTransformer(Uri destinationPrefix) _destinationPrefix = destinationPrefix; } - public override async Task TransformResponseAsync(HttpContext context, HttpResponseMessage response) + public override ValueTask TransformResponseTrailersAsync(HttpContext context, HttpResponseMessage response) { var location = response.Headers.Location; @@ -24,7 +24,7 @@ public override async Task TransformResponseAsync(HttpContext context, HttpRespo var relative = location.PathAndQuery; response.Headers.Location = new Uri(relative, UriKind.Relative); } - await base.TransformResponseAsync(context, response); + return base.TransformResponseTrailersAsync(context, response); } } } \ No newline at end of file diff --git a/main/src/ReCode.Cocoon.Proxy/ReCode.Cocoon.Proxy.csproj b/main/src/ReCode.Cocoon.Proxy/ReCode.Cocoon.Proxy.csproj index 1a38af6..88f3201 100644 --- a/main/src/ReCode.Cocoon.Proxy/ReCode.Cocoon.Proxy.csproj +++ b/main/src/ReCode.Cocoon.Proxy/ReCode.Cocoon.Proxy.csproj @@ -13,7 +13,7 @@ - + From fdd7e2b5196ee059c3b10b519d4c7f05535d4a70 Mon Sep 17 00:00:00 2001 From: Howard Richards Date: Wed, 16 Feb 2022 09:09:37 +0000 Subject: [PATCH 2/3] Fixed typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f21aa5e..8798bfa 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ Once running the following endpoints will now be available: * http://localhost:5003 - MVC * http://localhost:5005 - BlazorServer -## Running tests with playwrite +## Running tests with PlayWright Install the CLI tooling. ``` From f103816e2869c961c5ec60f6a2193802f340e7d8 Mon Sep 17 00:00:00 2001 From: Howard Richards Date: Wed, 20 Apr 2022 16:01:51 +0100 Subject: [PATCH 3/3] Upgraded to Yarp.ReverseProxy v1.0.1 for security update --- main/src/ReCode.Cocoon.Proxy/ReCode.Cocoon.Proxy.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/src/ReCode.Cocoon.Proxy/ReCode.Cocoon.Proxy.csproj b/main/src/ReCode.Cocoon.Proxy/ReCode.Cocoon.Proxy.csproj index 88f3201..bc6202e 100644 --- a/main/src/ReCode.Cocoon.Proxy/ReCode.Cocoon.Proxy.csproj +++ b/main/src/ReCode.Cocoon.Proxy/ReCode.Cocoon.Proxy.csproj @@ -13,7 +13,7 @@ - +