[Fixes #4766] Remove disable buffering feature from our action result classes

This commit is contained in:
Kiran Challa 2016-07-15 10:22:40 -07:00
parent 52e4ca7232
commit 26b3b5ea7b
8 changed files with 0 additions and 171 deletions

View File

@ -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 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
response.ContentType = context.ContentType.ToString();
}
var bufferingFeature = context.HttpContext.Features.Get<IHttpBufferingFeature>();
bufferingFeature?.DisableResponseBuffering();
await valueAsStream.CopyToAsync(response.Body);
}
}

View File

@ -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 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{
var response = context.HttpContext.Response;
var bufferingFeature = response.HttpContext.Features.Get<IHttpBufferingFeature>();
bufferingFeature?.DisableResponseBuffering();
return response.Body.WriteAsync(result.FileContents, offset: 0, count: result.FileContents.Length);
}
}

View File

@ -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 @@ namespace Microsoft.AspNetCore.Mvc.Internal
using (result.FileStream)
{
var bufferingFeature = response.HttpContext.Features.Get<IHttpBufferingFeature>();
bufferingFeature?.DisableResponseBuffering();
await result.FileStream.CopyToAsync(outputStream, BufferSize);
}
}

View File

@ -5,7 +5,6 @@ using System.IO;
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 @@ namespace Microsoft.AspNetCore.Mvc
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<IHttpBufferingFeature>(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<IHttpBufferingFeature>();
Assert.True(bufferingFeature.DisableResponseBufferingInvoked);
}
public static TheoryData<MediaTypeHeaderValue, string, string, string, byte[]> ContentResultContentTypeData
{
get

View File

@ -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 @@ namespace Microsoft.AspNetCore.Mvc
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<IHttpBufferingFeature>(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 @@ namespace Microsoft.AspNetCore.Mvc
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;
}
}
}
}

View File

@ -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 @@ namespace Microsoft.AspNetCore.Mvc
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<IHttpBufferingFeature>(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();

View File

@ -87,35 +87,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
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<IHttpBufferingFeature>(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; }

View File

@ -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;
}
}
}