Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Allow proxy middleware to abort long running connections. #914

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack
/// </summary>
internal class ConditionalProxyMiddleware
{
private const int DefaultHttpBufferSize = 4096;

private readonly HttpClient _httpClient;
private readonly RequestDelegate _next;
private readonly ConditionalProxyMiddlewareOptions _options;
Expand Down Expand Up @@ -93,7 +95,12 @@ private async Task<bool> PerformProxyRequest(HttpContext context)

// SendAsync removes chunking from the response. This removes the header so it doesn't expect a chunked response.
context.Response.Headers.Remove("transfer-encoding");
await responseMessage.Content.CopyToAsync(context.Response.Body);

using (var responseStream = await responseMessage.Content.ReadAsStreamAsync())
{
await responseStream.CopyToAsync(context.Response.Body, DefaultHttpBufferSize, context.RequestAborted);
}

return true;
}
}
Expand Down