Skip to content

Commit

Permalink
Add extension to assist with minimal API.
Browse files Browse the repository at this point in the history
  • Loading branch information
twitchax committed Feb 14, 2022
1 parent 804525f commit 944ac8b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Core/AspNetCore.Proxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>AspNetCore.Proxy</AssemblyName>
<PackageId>AspNetCore.Proxy</PackageId>
<Version>4.2.1</Version>
<Version>4.3.0</Version>
<PackageProjectUrl>https://github.com/twitchax/aspnetcore.proxy</PackageProjectUrl>

<TargetFrameworks>netcoreapp3.1;netstandard2.0;net5.0</TargetFrameworks>
Expand Down
52 changes: 45 additions & 7 deletions src/Core/Extensions/Basic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,45 @@ public static void RunProxy(this IApplicationBuilder app, Action<IProxyBuilder>
/// <summary>
/// Proxies a request inside of a controller's method body from the request on the controller's route.
/// </summary>
/// <param name="controller">The ASP.NET <see cref="ControllerBase"/>.</param>
/// <param name="context">The ASP.NET <see cref="HttpContext"/>.</param>
/// <param name="httpEndpoint">The HTTP endpoint to use.</param>
/// <param name="wsEndpoint">The WS endpoint to use.</param>
/// <param name="httpProxyOptions">The HTTP options.</param>
/// <param name="wsProxyOptions">The WS options.</param>
/// <returns>A <see cref="Task"/> which completes when the request has been successfully proxied and written to the response.</returns>
public static Task ProxyAsync(this ControllerBase controller, string httpEndpoint, string wsEndpoint, HttpProxyOptions httpProxyOptions = null, WsProxyOptions wsProxyOptions = null)
public static Task ProxyAsync(this HttpContext context, string httpEndpoint, string wsEndpoint, HttpProxyOptions httpProxyOptions = null, WsProxyOptions wsProxyOptions = null)
{
var httpProxy = new HttpProxy((c, a) => new ValueTask<string>(httpEndpoint), httpProxyOptions);
var wsProxy = new WsProxy((c, a) => new ValueTask<string>(wsEndpoint), wsProxyOptions);
var proxy = new Builders.Proxy(null, httpProxy, wsProxy);
return controller.HttpContext.ExecuteProxyOperationAsync(proxy);
return context.ExecuteProxyOperationAsync(proxy);
}

/// <summary>
/// Proxies a request inside of a controller's method body from the request on the controller's route.
/// </summary>
/// <param name="controller">The ASP.NET <see cref="ControllerBase"/>.</param>
/// <param name="httpEndpoint">The HTTP endpoint to use.</param>
/// <param name="wsEndpoint">The WS endpoint to use.</param>
/// <param name="httpProxyOptions">The HTTP options.</param>
/// <param name="wsProxyOptions">The WS options.</param>
/// <returns>A <see cref="Task"/> which completes when the request has been successfully proxied and written to the response.</returns>
public static Task ProxyAsync(this ControllerBase controller, string httpEndpoint, string wsEndpoint, HttpProxyOptions httpProxyOptions = null, WsProxyOptions wsProxyOptions = null)
{
return controller.HttpContext.ProxyAsync(httpEndpoint, wsEndpoint, httpProxyOptions, wsProxyOptions);
}

/// <summary>
/// Proxies a request inside of a controller's method body from the request on the controller's route.
/// </summary>
/// <param name="context">The ASP.NET <see cref="HttpContext"/>.</param>
/// <param name="httpEndpoint">The HTTP endpoint to use.</param>
/// <param name="httpProxyOptions">The HTTP options.</param>
/// <returns>A <see cref="Task"/> which completes when the request has been successfully proxied and written to the response.</returns>
public static Task HttpProxyAsync(this HttpContext context, string httpEndpoint, HttpProxyOptions httpProxyOptions = null)
{
var httpProxy = new HttpProxy((_, _) => new ValueTask<string>(httpEndpoint), httpProxyOptions);
return context.ExecuteHttpProxyOperationAsync(httpProxy);
}

/// <summary>
Expand All @@ -289,8 +316,20 @@ public static Task ProxyAsync(this ControllerBase controller, string httpEndpoin
/// <returns>A <see cref="Task"/> which completes when the request has been successfully proxied and written to the response.</returns>
public static Task HttpProxyAsync(this ControllerBase controller, string httpEndpoint, HttpProxyOptions httpProxyOptions = null)
{
var httpProxy = new HttpProxy((c, a) => new ValueTask<string>(httpEndpoint), httpProxyOptions);
return controller.HttpContext.ExecuteHttpProxyOperationAsync(httpProxy);
return controller.HttpContext.HttpProxyAsync(httpEndpoint, httpProxyOptions);
}

/// <summary>
/// Proxies a request inside of a controller's method body from the request on the controller's route.
/// </summary>
/// <param name="context">The ASP.NET <see cref="HttpContext"/>.</param>
/// <param name="wsEndpoint">The WS endpoint to use.</param>
/// <param name="wsProxyOptions">The WS options.</param>
/// <returns>A <see cref="Task"/> which completes when the request has been successfully proxied and written to the response.</returns>
public static Task WsProxyAsync(this HttpContext context, string wsEndpoint, WsProxyOptions wsProxyOptions = null)
{
var wsProxy = new WsProxy((_, _) => new ValueTask<string>(wsEndpoint), wsProxyOptions);
return context.ExecuteWsProxyOperationAsync(wsProxy);
}

/// <summary>
Expand All @@ -302,8 +341,7 @@ public static Task HttpProxyAsync(this ControllerBase controller, string httpEnd
/// <returns>A <see cref="Task"/> which completes when the request has been successfully proxied and written to the response.</returns>
public static Task WsProxyAsync(this ControllerBase controller, string wsEndpoint, WsProxyOptions wsProxyOptions = null)
{
var wsProxy = new WsProxy((c, a) => new ValueTask<string>(wsEndpoint), wsProxyOptions);
return controller.HttpContext.ExecuteWsProxyOperationAsync(wsProxy);
return controller.HttpContext.WsProxyAsync(wsEndpoint, wsProxyOptions);
}

#endregion
Expand Down

0 comments on commit 944ac8b

Please sign in to comment.