Skip to content

Don't set content-type if not content #449

@jherven

Description

@jherven

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";
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Triage 🔍Label added to new issues which need Triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions