Exemple #1
0
 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)));
 }
Exemple #3
0
 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);
             }
         }
     }
 }