diff --git a/src/ReverseProxy/Forwarder/IHttpForwarderExtensions.cs b/src/ReverseProxy/Forwarder/IHttpForwarderExtensions.cs index 259291285..c9313360e 100644 --- a/src/ReverseProxy/Forwarder/IHttpForwarderExtensions.cs +++ b/src/ReverseProxy/Forwarder/IHttpForwarderExtensions.cs @@ -5,6 +5,7 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; namespace Yarp.ReverseProxy.Forwarder; @@ -13,6 +14,28 @@ namespace Yarp.ReverseProxy.Forwarder; /// public static class IHttpForwarderExtensions { + /// + /// Forwards the incoming request to the destination server, and the response back to the client. + /// + /// The forwarder instance. + /// The HttpContext to forward. + /// The url prefix for where to forward the request to. + /// Config for the outgoing request. + /// Transform function to apply to the forwarded request. + /// The status of a forwarding operation. + public static ValueTask SendAsync(this IHttpForwarder forwarder, HttpContext context, string destinationPrefix, + ForwarderRequestConfig? requestConfig = null, Func? requestTransform = null) + { + ArgumentNullException.ThrowIfNull(forwarder); + ArgumentNullException.ThrowIfNull(context); + + requestConfig ??= ForwarderRequestConfig.Empty; + var transformer = requestTransform is null ? HttpTransformer.Default : new RequestTransformer(requestTransform); + var httpClientProvider = context.RequestServices.GetRequiredService(); + + return forwarder.SendAsync(context, destinationPrefix, httpClientProvider.HttpClient, requestConfig, transformer); + } + /// /// Forwards the incoming request to the destination server, and the response back to the client. ///