diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Formatters/StreamOutputFormatter.cs b/src/Microsoft.AspNetCore.Mvc.Core/Formatters/StreamOutputFormatter.cs index 49ba9d9956..a1a748a0f7 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Formatters/StreamOutputFormatter.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Formatters/StreamOutputFormatter.cs @@ -4,7 +4,6 @@ using System; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; namespace Microsoft.AspNetCore.Mvc.Formatters { @@ -47,9 +46,6 @@ public async Task WriteAsync(OutputFormatterWriteContext context) response.ContentType = context.ContentType.ToString(); } - var bufferingFeature = context.HttpContext.Features.Get(); - bufferingFeature?.DisableResponseBuffering(); - await valueAsStream.CopyToAsync(response.Body); } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileContentResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileContentResultExecutor.cs index 4624962f93..a2e68dd6f0 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileContentResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileContentResultExecutor.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; -using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Mvc.Internal @@ -24,9 +23,6 @@ private static Task WriteFileAsync(ActionContext context, FileContentResult resu { var response = context.HttpContext.Response; - var bufferingFeature = response.HttpContext.Features.Get(); - bufferingFeature?.DisableResponseBuffering(); - return response.Body.WriteAsync(result.FileContents, offset: 0, count: result.FileContents.Length); } } diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileStreamResultExecutor.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileStreamResultExecutor.cs index 5b38bb000d..f6785180b1 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileStreamResultExecutor.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/FileStreamResultExecutor.cs @@ -1,10 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Mvc.Internal @@ -32,9 +29,6 @@ private static async Task WriteFileAsync(ActionContext context, FileStreamResult using (result.FileStream) { - var bufferingFeature = response.HttpContext.Features.Get(); - bufferingFeature?.DisableResponseBuffering(); - await result.FileStream.CopyToAsync(outputStream, BufferSize); } } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/ContentResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/ContentResultTest.cs index 201a94b613..09a29560f5 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/ContentResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/ContentResultTest.cs @@ -5,7 +5,6 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.TestCommon; using Microsoft.AspNetCore.Mvc.ViewComponents; @@ -43,35 +42,6 @@ public async Task ContentResult_Response_NullContent_SetsContentTypeAndEncoding( MediaTypeAssert.Equal("text/plain; charset=utf-7", httpContext.Response.ContentType); } - [Fact] - public async Task ContentResult_DisablesResponseBuffering_IfBufferingFeatureAvailable() - { - // Arrange - var data = "Test Content"; - var contentResult = new ContentResult - { - Content = data, - ContentType = new MediaTypeHeaderValue("text/plain") - { - Encoding = Encoding.ASCII - }.ToString() - }; - var httpContext = GetHttpContext(); - httpContext.Features.Set(new TestBufferingFeature()); - var memoryStream = new MemoryStream(); - httpContext.Response.Body = memoryStream; - var actionContext = GetActionContext(httpContext); - - // Act - await contentResult.ExecuteResultAsync(actionContext); - - // Assert - Assert.Equal("text/plain; charset=us-ascii", httpContext.Response.ContentType); - Assert.Equal(Encoding.ASCII.GetString(memoryStream.ToArray()), data); - var bufferingFeature = (TestBufferingFeature)httpContext.Features.Get(); - Assert.True(bufferingFeature.DisableResponseBufferingInvoked); - } - public static TheoryData ContentResultContentTypeData { get diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileContentResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileContentResultTest.cs index 6b1be772bb..4a2cd2b717 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileContentResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileContentResultTest.cs @@ -4,7 +4,6 @@ using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.TestCommon; @@ -93,32 +92,6 @@ public async Task ExecuteResultAsync_SetsSuppliedContentTypeAndEncoding() Assert.Equal(expectedContentType, httpContext.Response.ContentType); } - [Fact] - public async Task DisablesResponseBuffering_IfBufferingFeatureAvailable() - { - // Arrange - var expectedContentType = "text/foo; charset=us-ascii"; - var buffer = new byte[] { 1, 2, 3, 4, 5 }; - - var httpContext = GetHttpContext(); - var bufferingFeature = new TestBufferingFeature(); - httpContext.Features.Set(bufferingFeature); - var outStream = new MemoryStream(); - httpContext.Response.Body = outStream; - - var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); - - var result = new FileContentResult(buffer, expectedContentType); - - // Act - await result.ExecuteResultAsync(context); - - // Assert - Assert.Equal(buffer, outStream.ToArray()); - Assert.Equal(expectedContentType, httpContext.Response.ContentType); - Assert.True(bufferingFeature.DisableResponseBufferingInvoked); - } - private static IServiceCollection CreateServices() { var services = new ServiceCollection(); @@ -137,22 +110,5 @@ private static HttpContext GetHttpContext() return httpContext; } - - private class TestBufferingFeature : IHttpBufferingFeature - { - public bool DisableResponseBufferingInvoked { get; private set; } - - public bool DisableRequestBufferingInvoked { get; private set; } - - public void DisableRequestBuffering() - { - DisableRequestBufferingInvoked = true; - } - - public void DisableResponseBuffering() - { - DisableResponseBufferingInvoked = true; - } - } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileStreamResultTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileStreamResultTest.cs index 4be0a92434..e3074a8eed 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/FileStreamResultTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/FileStreamResultTest.cs @@ -3,11 +3,9 @@ using System.IO; using System.Linq; -using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.TestCommon; @@ -141,34 +139,6 @@ public async Task SetsSuppliedContentTypeAndEncoding() Assert.Equal(expectedContentType, httpContext.Response.ContentType); } - [Fact] - public async Task DisablesResponseBuffering_IfBufferingFeatureAvailable() - { - // Arrange - var expectedContentType = "text/foo; charset=us-ascii"; - var expected = Encoding.ASCII.GetBytes("Test data"); - - var originalStream = new MemoryStream(expected); - - var httpContext = GetHttpContext(); - var bufferingFeature = new TestBufferingFeature(); - httpContext.Features.Set(bufferingFeature); - var outStream = new MemoryStream(); - httpContext.Response.Body = outStream; - - var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); - var result = new FileStreamResult(originalStream, expectedContentType); - - // Act - await result.ExecuteResultAsync(actionContext); - - // Assert - var outBytes = outStream.ToArray(); - Assert.Equal(expected, outBytes); - Assert.Equal(expectedContentType, httpContext.Response.ContentType); - Assert.True(bufferingFeature.DisableResponseBufferingInvoked); - } - private static IServiceCollection CreateServices() { var services = new ServiceCollection(); diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/StreamOutputFormatterTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/StreamOutputFormatterTest.cs index 0fe79e68f6..5f29c2c59e 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/StreamOutputFormatterTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Formatters/StreamOutputFormatterTest.cs @@ -87,35 +87,6 @@ public void CanWriteResult_OnlyActsOnStreams(Type type) Assert.False(result); } - [Fact] - public async Task DisablesResponseBuffering_IfBufferingFeatureAvailable() - { - // Arrange - var formatter = new StreamOutputFormatter(); - - var expected = Encoding.UTF8.GetBytes("Test data"); - - var httpContext = new DefaultHttpContext(); - var body = new MemoryStream(); - httpContext.Response.Body = body; - - var bufferingFeature = new TestBufferingFeature(); - httpContext.Features.Set(bufferingFeature); - - var context = new OutputFormatterWriteContext( - httpContext, - new TestHttpResponseStreamWriterFactory().CreateWriter, - typeof(Stream), - new MemoryStream(expected)); - - // Act - await formatter.WriteAsync(context); - - // Assert - Assert.Equal(expected, body.ToArray()); - Assert.True(bufferingFeature.DisableResponseBufferingInvoked); - } - private class SimplePOCO { public int Id { get; set; } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/TestBufferingFeature.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/TestBufferingFeature.cs deleted file mode 100644 index 2118983a65..0000000000 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/TestBufferingFeature.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Http.Features; - -namespace Microsoft.AspNetCore.Mvc -{ - internal class TestBufferingFeature : IHttpBufferingFeature - { - public bool DisableResponseBufferingInvoked { get; private set; } - - public bool DisableRequestBufferingInvoked { get; private set; } - - public void DisableRequestBuffering() - { - DisableRequestBufferingInvoked = true; - } - - public void DisableResponseBuffering() - { - DisableResponseBufferingInvoked = true; - } - } -}