internal static async Task ProxyRequest( this HttpContext context, Uri destinationUri, ProxyOptions proxyOptions, IHttpClientFactory httpClientFactory) { using (var requestMessage = context.CreateProxyHttpRequest(destinationUri)) { if (proxyOptions.PrepareRequest != null) { var prepareRequestContext = new PrepareRequestContext(context.Request, context.Connection, requestMessage); proxyOptions.PrepareRequest(prepareRequestContext); } var httpClient = httpClientFactory.CreateClient("ProxyKit"); using (var responseMessage = await httpClient.SendAsync( requestMessage, HttpCompletionOption.ResponseHeadersRead, context.RequestAborted)) { await context.CopyProxyHttpResponse(responseMessage); } } }
public ProxyMiddleware(RequestDelegate _, ProxyOptions proxyOptions, IHttpClientFactory httpClientFactory) { _proxyOptions = proxyOptions; _httpClientFactory = httpClientFactory; }
private WebSocketProxyMiddleware( RequestDelegate next, IOptionsMonitor <ProxyOptions> options, ILogger <WebSocketProxyMiddleware> logger) { _next = next; _options = options.CurrentValue; _logger = logger; }
public WebSocketProxyMiddleware( RequestDelegate next, ProxyOptions options, Uri destinationUri, ILogger <WebSocketProxyMiddleware> logger) { _next = next; _options = options; _destinationUri = destinationUri; _logger = logger; }
public WebSocketProxyMiddleware( RequestDelegate next, IOptionsMonitor <ProxyOptions> options, Uri destinationUri, ILogger <WebSocketProxyMiddleware> logger) { _next = next; _options = options.CurrentValue; _destinationUri = destinationUri; _logger = logger; }
internal static async Task ProxyRequest( this HttpContext context, Uri destinationUri, ProxyOptions proxyOptions, IHttpClientFactory httpClientFactory) { using (var requestMessage = context.CreateProxyHttpRequest(destinationUri)) { if (proxyOptions.PrepareRequest != null) { var prepareRequestContext = new PrepareRequestContext(context.Request, context.Connection, requestMessage); proxyOptions.PrepareRequest(prepareRequestContext); } var httpClient = httpClientFactory.CreateClient("ProxyKit"); try { using (var responseMessage = await httpClient.SendAsync( requestMessage, HttpCompletionOption.ResponseHeadersRead, context.RequestAborted)) { await context.CopyProxyHttpResponse(responseMessage); } } catch (TaskCanceledException ex) { if (RequestHasTimedOut(ex)) { context.Response.StatusCode = 504; return; } throw; } catch (HttpRequestException ex) { if (UpstreamIsUnavailable(ex)) { context.Response.StatusCode = 503; return; } throw; } } }
/// <summary> /// Runs proxy forwarding requests to downstream server. /// </summary> /// <param name="app"> /// The application builder. /// </param> /// <param name="handleProxyRequest"> /// A delegate that can resolve the destination Uri. /// </param> public static void RunProxy( this IApplicationBuilder app, HandleProxyRequest handleProxyRequest) { if (app == null) { throw new ArgumentNullException(nameof(app)); } var proxyOptions = new ProxyOptions { HandleProxyRequest = handleProxyRequest, }; app.UseMiddleware <ProxyMiddleware>(proxyOptions); }
/// <summary> /// Runs proxy forwarding requests to downstream server. /// </summary> /// <param name="app"> /// The application builder. /// </param> /// <param name="pathMatch"> /// Branches the request pipeline based on matches of the given /// request path. If the request path starts with the given path, /// the branch is executed. /// </param> /// <param name="handleProxyRequest"> /// A delegate that can resolve the destination Uri. /// </param> public static void RunProxy( this IApplicationBuilder app, PathString pathMatch, HandleProxyRequest handleProxyRequest) { if (app == null) { throw new ArgumentNullException(nameof(app)); } var proxyOptions = new ProxyOptions { HandleProxyRequest = handleProxyRequest, }; app.Map(pathMatch, appInner => { appInner.UseMiddleware <ProxyMiddleware>(proxyOptions); }); }
public ProxyMiddleware(RequestDelegate _, ProxyOptions proxyOptions) { _proxyOptions = proxyOptions; }