HttpResponse body infrastructure changes #376
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
Milestone
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
The text was updated successfully, but these errors were encountered: