Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
[Fixes #4766] Remove disable buffering feature from our action result…
Browse files Browse the repository at this point in the history
… classes
  • Loading branch information
kichalla committed Jul 18, 2016
1 parent 52e4ca7 commit d46ad91
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Features;

namespace Microsoft.AspNetCore.Mvc.Formatters
{
Expand Down Expand Up @@ -47,9 +46,6 @@ public async Task WriteAsync(OutputFormatterWriteContext context)
response.ContentType = context.ContentType.ToString();
}

var bufferingFeature = context.HttpContext.Features.Get<IHttpBufferingFeature>();
bufferingFeature?.DisableResponseBuffering();

await valueAsStream.CopyToAsync(response.Body);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,9 +23,6 @@ private static Task WriteFileAsync(ActionContext context, FileContentResult resu
{
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -32,9 +29,6 @@ private static async Task WriteFileAsync(ActionContext context, FileStreamResult

using (result.FileStream)
{
var bufferingFeature = response.HttpContext.Features.Get<IHttpBufferingFeature>();
bufferingFeature?.DisableResponseBuffering();

await result.FileStream.CopyToAsync(outputStream, BufferSize);
}
}
Expand Down
44 changes: 0 additions & 44 deletions test/Microsoft.AspNetCore.Mvc.Core.Test/FileContentResultTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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();
Expand All @@ -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;
}
}
}
}
30 changes: 0 additions & 30 deletions test/Microsoft.AspNetCore.Mvc.Core.Test/FileStreamResultTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<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; }
Expand Down
24 changes: 0 additions & 24 deletions test/Microsoft.AspNetCore.Mvc.Core.Test/TestBufferingFeature.cs

This file was deleted.

0 comments on commit d46ad91

Please sign in to comment.