HttpListenerResponse.ContentType exception information is wrong or outdated
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
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.
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.
Tagging subscribers to this area: @dotnet/ncl