dotnet-api-docs icon indicating copy to clipboard operation
dotnet-api-docs copied to clipboard

HttpListenerResponse.ContentType exception information is wrong or outdated

Open markusschaber opened this issue 10 months ago • 3 comments

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

markusschaber avatar Mar 10 '25 09:03 markusschaber

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost avatar Mar 10 '25 09:03 ghost

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost avatar Mar 10 '25 09:03 ghost

Tagging subscribers to this area: @dotnet/ncl