Open
Description
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
ArgumentNullExceptionThe value specified for a set operation is null.
ArgumentExceptionThe 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
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