From 54884459bd3bc54fc70b13ae0ac29fdfa0f12c09 Mon Sep 17 00:00:00 2001 From: Matt Perry Date: Wed, 3 May 2017 22:19:42 -0400 Subject: [PATCH] Allow proxy middleware to abort long running connections. --- .../Webpack/ConditionalProxyMiddleware.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.SpaServices/Webpack/ConditionalProxyMiddleware.cs b/src/Microsoft.AspNetCore.SpaServices/Webpack/ConditionalProxyMiddleware.cs index 5a56c81..be1cc38 100644 --- a/src/Microsoft.AspNetCore.SpaServices/Webpack/ConditionalProxyMiddleware.cs +++ b/src/Microsoft.AspNetCore.SpaServices/Webpack/ConditionalProxyMiddleware.cs @@ -16,6 +16,7 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack /// internal class ConditionalProxyMiddleware { + private const int BUFFER_SIZE = 1024; private readonly HttpClient _httpClient; private readonly RequestDelegate _next; private readonly ConditionalProxyMiddlewareOptions _options; @@ -93,7 +94,12 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack // 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, BUFFER_SIZE, context.RequestAborted); + } + return true; } }