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

HttpResponse body infrastructure changes #376

Open
Tratcher opened this issue Jul 26, 2019 · 0 comments
Open

HttpResponse body infrastructure changes #376

Tratcher opened this issue Jul 26, 2019 · 0 comments
Labels
3.0.0 Announcements related to ASP.NET Core 3.0 Announcement Breaking change Documented The breaking change has been published to the .NET Core docs Migrated

Comments

@Tratcher
Copy link
Member

Tratcher commented Jul 26, 2019

TLDR: The infrastructure backing HttpResponse bodies has changed. If you're using HttpResponse directly you should not need to make any code changes. Read further if you were wrapping or replacing HttpResponse.Body or accessing HttpContext.Features.

Version: 3.0.0-preview8

Background:
HttpContext, HttpRequest, HttpResponse are backed by an abstraction called Features. This allows functionality to be provided by different components in the pipeline without wrapping the entire HttpContext.

In 2.x there are three APIs associated with the response body: IHttpResponseFeature.Body, IHttpSendFileFeature.SendFileAsync, and IHttpBufferingFeature.DisableResponseBuffering, but the later two were rarely implemented or used.

Over the course of 3.0 several new response body APIs were added:
IHttpResponseBodyPipeFeature
IHttpResponseStartFeature.StartAsync
IHttpResponseCompleteFeature.CompleteAsync

Problem: With so many APIs it became too hard for middleware to properly intercept the response body. It was also hard for calling code to rely on those features being present on all servers.

Fix: Consolidate the response body APIs onto a single new feature interface IHttpResponseBodyFeature. HttpResponse has been updated accordingly, and each server has been updated to provide at least a minimal implementation for all of these APIs. We'll iterate to provide more fully featured implementations in each server but that won't require any more API changes.

Note if you replace HttpResponse.Body it will now replace the entire IHttpResponseBodyFeature with a wrapper around your given stream using StreamResponseBodyFeature to provide default implementations for all of the expected APIs. Setting back the original stream will undo this change.
https://github.com/aspnet/AspNetCore/blob/4aebd29abca80242f5ff9e89e07d4f1b28788a44/src/Http/Http/src/Internal/DefaultHttpResponse.cs#L67-L89

Breaking change dotnet/aspnetcore#12328

Obsolete existing 2.x APIs
IHttpResponseFeature.Body
IHttpSendFileFeature
IHttpBufferingFeature

Deleted feature interfaces that were introduced earlier in 3.0.
IHttpResponseBodyPipeFeature
IHttpResponseStartFeature
IHttpResponseCompleteFeature

In a future major release we plan to refactor the request body features as well dotnet/aspnetcore#12620.

See dotnet/aspnetcore#12635 for discussion.

This announcement has been migrated to: dotnet/docs#14832

@Tratcher Tratcher added Announcement Breaking change 3.0.0 Announcements related to ASP.NET Core 3.0 labels Jul 26, 2019
@Tratcher Tratcher added this to the 3.0.0-preview8 milestone Jul 26, 2019
@aspnet aspnet locked as resolved and limited conversation to collaborators Jul 26, 2019
@scottaddie scottaddie added the Documented The breaking change has been published to the .NET Core docs label Dec 17, 2019
@BrennanConroy BrennanConroy removed their assignment Jan 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.0.0 Announcements related to ASP.NET Core 3.0 Announcement Breaking change Documented The breaking change has been published to the .NET Core docs Migrated
Projects
None yet
Development

No branches or pull requests

3 participants