Don't set content-type if not content
jherven opened this issue · 2 comments
jherven commented
Summary
Using this library in a dotnet core application forcefully adds content-type "text/html" (when not set) even if there's no content. This isn't always desired and I think it's neither expected when there is no content for the response.
Motivation and goals
- Some clients break when there is a content-type set but no content
- At least for my migrated projects this doesn't mimic the behavior I had in the old application
Risks / unknowns
If somebody already using this library relies on this header always being set this change may break something
Detailed design
The change I've done for now is very simple.
src/Microsoft.AspNetCore.SystemWebAdapters.CoreServices/SetDefaultResponseHeadersMiddleware.cs -> WriteDefaultContentType
Added new criteria "hasContent"
bool hasContent = context.Response.ContentLength.HasValue;
if (hasContent && context.Response.Headers.ContentType.Count == 0)
{
context.Response.Headers.ContentType = "text/html";
}
twsouthwick commented
Thanks @jherven - have you verified this is the same behavior as on ASP.NET Framework? If so, would you be willing to submit a PR?