public ProxyMiddleware(RequestDelegate next, IOptions <ProxyOptions> options) { this.next = next; this.options = options.Value; }
public static IApplicationBuilder UseProxy(this IApplicationBuilder builder, ProxyOptions options) { return(builder.UseMiddleware <ProxyMiddleware>(Options.Create(options))); }
public static async Task ProxyRequest(this HttpContext context, Uri destinationUri, ProxyOptions options) { if (!context.WebSockets.IsWebSocketRequest) { using (var requestMessage = context.CreateProxyHttpRequest(destinationUri)) { if (options.HeadersToAppend != null) { foreach (var headerToAdd in options.HeadersToAppend) { requestMessage.Headers.Add(headerToAdd.Key, headerToAdd.Value); } } using (var responseMessage = await context.SendProxyHttpRequest(requestMessage)) { await context.CopyProxyHttpResponse(responseMessage); } } } }