Skip to content

HttpListenerResponse.ContentType exception information is wrong or outdated #11070

Open
@markusschaber

Description

@markusschaber

Type of issue

Outdated article

Description

It seems that setting this property to null or an empty string removes the content type header, instead of throwing the documented exceptions.

Exceptions
ArgumentNullException

The value specified for a set operation is null.
ArgumentException

The value specified for a set operation is an empty string ("").

As the implementation actually provides useful behavior, I'm in favor of updating the documentation.

See the original source: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.HttpListener/src/System/Net/HttpListenerResponse.cs#L36

      public string? ContentType
       {
           get => Headers[HttpKnownHeaderNames.ContentType];
           set
           {
               CheckDisposed();
               if (string.IsNullOrEmpty(value))
               {
                   Headers.Remove(HttpKnownHeaderNames.ContentType);
               }
               else
               {
                   Headers.Set(HttpKnownHeaderNames.ContentType, value);
               }
           }
       }

Page URL

https://learn.microsoft.com/en-us/dotnet/api/System.Net.HttpListenerResponse.ContentType?view=net-8.0

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Net/HttpListenerResponse.xml

Document Version Independent Id

77a14fab-0939-53e8-cdb7-f59d262e911e

Platform Id

e73e3459-e08a-db79-bce3-9d157059a7aa

Article author

@karelz

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.NetuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions