public async Task Invoke(HttpContext context) { PathString remainingPath; context.Request.EnableBuffering(); var matchingProxy = _proxies.Keys.FirstOrDefault(k => context.Request.Path.StartsWithSegments(k, out remainingPath)); if (!string.IsNullOrEmpty(matchingProxy)) { var http = _httpFactory.CreateClient(); var baseUri = _proxies[matchingProxy]; var builder = new HttpRequestMessageBuilder(context.Request.Method); builder.AddUri(baseUri + remainingPath + context.Request.QueryString); builder.AddContentAndHeaders(context.Request.Body, context.Request.Headers); builder.AddHost(baseUri.Authority); var request = builder.Build(); using var response = await http.SendAsync(request); await ModifyResponse(context.Response, response); return; } await _next.Invoke(context); }