Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```
Expand Down
18 changes: 9 additions & 9 deletions main/src/ReCode.Cocoon.Proxy/Proxy/CocoonProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> _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<CocoonProxy> logger, IHttpProxy httpProxy, CocoonProxyOptions? proxyOptions)
public CocoonProxy(IConfiguration configuration, ILogger<CocoonProxy> logger, IHttpForwarder httpForwarder, CocoonProxyOptions? proxyOptions)
{
_httpProxy = httpProxy;
_httpProxy = httpForwarder;
_destinationPrefix = configuration
.GetValue<string>("Cocoon:Proxy:DestinationPrefix");

Expand All @@ -37,7 +37,7 @@ public CocoonProxy(IConfiguration configuration, ILogger<CocoonProxy> logger, IH
throw new InvalidOperationException("Invalid DestinationPrefix");
}

logger.LogInformation($"Cocoon Proxy backend: {destinationPrefixUri}");
logger?.LogInformation($"Cocoon Proxy backend: {destinationPrefixUri}");

_backendUrls = CocoonProxyExclusions.CreateExclusionSet(configuration);

Expand All @@ -62,9 +62,9 @@ public CocoonProxy(IConfiguration configuration, ILogger<CocoonProxy> logger, IH
{
timeout = TimeSpan.FromSeconds(30);
}
_requestOptions = new RequestProxyOptions
_requestOptions = new ForwarderRequestConfig
{
Timeout = timeout
ActivityTimeout = timeout
};
}

Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,7 +18,7 @@ public static IReverseProxyBuilder AddCocoonProxy(this IServiceCollection servic
services.AddSingleton<CocoonProxy>(provider => new CocoonProxy(
configuration,
provider.GetService<ILogger<CocoonProxy>>(),
provider.GetService<IHttpProxy>(), cocoonProxyOptions));
provider.GetService<IHttpForwarder>(), cocoonProxyOptions));

return ReverseProxyBuilder(services, configuration);
}
Expand Down
6 changes: 3 additions & 3 deletions main/src/ReCode.Cocoon.Proxy/Proxy/RedirectTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;

Expand All @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion main/src/ReCode.Cocoon.Proxy/ReCode.Cocoon.Proxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="MessagePack" Version="2.2.85" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="5.0.1" />
<PackageReference Include="Yarp.ReverseProxy" Version="1.0.0-preview.10.21168.2" />
<PackageReference Include="Yarp.ReverseProxy" Version="1.0.1" />
</ItemGroup>

</Project>