Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling buffering for all requests. Fixes #3765. #3851

Merged
merged 1 commit into from
Dec 12, 2018

Conversation

alrod
Copy link
Member

@alrod alrod commented Dec 5, 2018

Fixes #3765
New ANCM disables gzip compression on "DisableRequestBuffering" call. With this change we will buffer all requests, not only proxy requests.

var bufferingFeature = context.Features.Get<IHttpBufferingFeature>();
bufferingFeature?.DisableRequestBuffering();
bufferingFeature?.DisableResponseBuffering();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed, we can't have these changes alone as they would potentially have a significant performance impact because of the buffering middleware introduced by proxies.

@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove project.

}

var originalBufferingFeature = httpContext.Features.Get<IHttpBufferingFeature>();
//var originalSendFileFeature = httpContext.Features.Get<IHttpSendFileFeature>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code.

var bufferStream = new BufferingWriteStream(originalResponseBody);
httpContext.Response.Body = bufferStream;
httpContext.Features.Set<IHttpBufferingFeature>(new HttpBufferingFeature(bufferStream, originalBufferingFeature));
//if (originalSendFileFeature != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -49,6 +49,7 @@

<ItemGroup>
<PackageReference Include="appinsights.testlogger" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.1.2-rtm-30908" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be referenced.

{
public static class ResponseBufferingMiddlewareExtensions
{
public static IApplicationBuilder UseResponseBuffering(this IApplicationBuilder builder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you missing some files? where is this being called?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we ever called the extension method (always had an explicit middleware registration), so this file is not really needed.

Copy link
Member Author

@alrod alrod Dec 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extension is called in ResponseBufferingMiddlewareTests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to avoid increasing the product surface just to be able to use their tests. This is a convenience method and we can build the tests without it (or bring it into the tests instead, but it isn't required).

Copy link
Member Author

@alrod alrod Dec 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to keep tests the same as in original repo. ResponseBufferingMiddlewareExtensions was used 8 times here. Anyway removed the class.

try
{
// Shim the response stream
var bufferStream = new BufferingWriteStream(originalResponseBody);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should either do it with this PR or open another work item to track this, we should not allocate a BufferStream with the size of the respondeBody for non-proxy functions. this has a perf impact and I missed it when initially took a dependency on BufferingMiddleware code from aspnet team.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least an issue needs to be opened to track this. This would be pretty straight forward to address, but a little outside of the scope of this change.

Copy link
Member Author

@alrod alrod Dec 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alrod alrod merged commit 00e62f4 into Azure:dev Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants