dotnet / systemweb-adapters

MIT License
336 stars 59 forks source link

Can't edit response headers in `PreSendRequestHeaders` stage if write in a buffering disabled response #531

Closed TaoziZ03 closed 1 month ago

TaoziZ03 commented 1 month ago

Describe the bug

Can't edit response headers in PreSendRequestHeaders stage if write a buffering disabled response

To Reproduce

// somewhere early
responseBodyFeature.DisableBuffering();

...

HttpApplication.ExecuteHandler((...)=>....)
// write a buffering disabled http response

HttpApplication.PreSendRequestHeaders((...) => response.AddHeader("a", ...); // it will throw here. In framework I still can change headers.

Exceptions (if any)

System.InvalidOperationException: 'The response headers cannot be modified because the response has already started.'
   at Microsoft.AspNetCore.HttpSys.Internal.HeaderCollection.ThrowIfReadOnly()
   at Microsoft.AspNetCore.HttpSys.Internal.HeaderCollection.set_Item(String key, StringValues value)
   at Microsoft.AspNetCore.Http.ParsingHelpers.AppendHeaderUnmodified(IHeaderDictionary headers, String key, StringValues values)
   at System.Web.HttpResponse.AppendHeader(String name, String value) in System.Web\HttpResponse.cs:line 269
   at System.Web.HttpResponse.AddHeader(String name, String value) in System.Web\HttpResponse.cs:line 264
......

Further technical details

I am testing 2.0.0-preview1.24405.2.