Fix IAsyncEnumerable controller methods to allow setting headers #57924
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix IAsyncEnumerable controller methods to allow setting headers
Description
When writing Json responses in MVC, we started flushing headers immediately before using
JsonSerializer
in order to avoid some unnecessary buffering in Kestrel when writing starts before headers are flushed. This had the unintended side-effect of makingIAsyncEnumerable<T>
MVC methods no longer able to set headers due to the fact that the whole method becomes theIAsyncEnumerable
and we pass that directly toJsonSerializer
, which means we've already flushed headers by the time the MVC method starts running. Resulting in an exception on the server and a bad response on the client.Fixes #57895
Customer Impact
MVC methods that returned
IAsyncEnumerable<T>
will now fail if they modify response headers.Regression?
Regressed from 8.0
Risk
Small targeted fix. Added test coverage for scenario.
Verification
Packaging changes reviewed?