Skip to content

Revert unintentional nullability changes and fix inconsistencies in StringContent ctrs #83423

Closed
@antonfirsov

Description

@antonfirsov

This is a follow-up on #81506 (comment). We introduced some inconsistencies and unintentional nullability changes in StringContent's constructors. Chronologically:

#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);
}

Metadata

Metadata

Assignees

Labels

api-approvedAPI 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 merged

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions