-
Couldn't load subscription status.
- Fork 5.2k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Net.Httpin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
This is a follow-up on #81506 (comment). We introduced some inconsistencies and unintentional nullability changes in StringContent's constructors. Chronologically:
- Add StringContent ctor providing tighter control over charset #17036 proposed new constructors before the introduction of nullable references to C#
- Annotate System.Net.Http for nullable #33268 changed all
mediaTypeargs to be nullable - We approving the new constructors, the comment with the fianal API suggestion did not takke into account the nullability changes implemented in Annotate System.Net.Http for nullable #33268, falsely "recommending" that nullability should be "reverted". It also proposed the argument
MediaTypeHeaderValue mediaTypeto be non-nullable, which is inconsistent with the then-existing API-s. - First try at implementing newly suggested ctor for providing tighter control over charset #63231 implemented the proposal in this form, and also altered existing
mediaTypeargs to be non-nullable- On top of that, the new constructors taking
MediaTypeHeaderValue mediaTypedon't do null-check on that arg, simply allowing the property to be set to null
Headers.ContentType = mediaType;
- On top of that, the new constructors taking
#81722 provides a minimal fix, however, since this was an unintentional change, I suggest to revisit it for .NET 8.0, relaxing nullability for all mediaType declarations, explicitly setting text/plain when null is being passed. This should be fairly trivial to implement.
public class StringContent : ByteArrayContent
{
- public StringContent(string content, MediaTypeHeaderValue mediaType);
+ public StringContent(string content, MediaTypeHeaderValue? mediaType);
- public StringContent(string content, Encoding? encoding, string mediaType);
+ public StringContent(string content, Encoding? encoding, string? mediaType);
- public StringContent(string content, Encoding? encoding, MediaTypeHeaderValue mediaType);
+ public StringContent(string content, Encoding? encoding, MediaTypeHeaderValue? mediaType);
}MihaZupan
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Net.Httpin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged