dotnet / dotnet/dotnet-api-docs
HttpListenerResponse.ContentType exception information is wrong or outdated
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
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
> [ArgumentNullException](https://learn.microsoft.com/en-us/dotnet/api/system.argumentnullexception?view=net-8.0)
>
> The value specified for a set operation is null.
> [ArgumentException](https://learn.microsoft.com/en-us/dotnet/api/system.argumentexception?view=net-8.0)
>
> 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
Contributor guide
Assessment
This issue has not been assessed yet.