Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] Default media type used when 'null' is passed to StringContent #81506 #83425

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public StringContent(string content, Encoding? encoding)
/// <param name="encoding">The encoding to use for the content.</param>
/// <param name="mediaType">The media type to use for the content.</param>
public StringContent(string content, Encoding? encoding, string mediaType)
: this(content, encoding, new MediaTypeHeaderValue(mediaType, (encoding ?? DefaultStringEncoding).WebName))
: this(content, encoding, new MediaTypeHeaderValue(mediaType ?? DefaultMediaType, (encoding ?? DefaultStringEncoding).WebName))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ public async Task Ctor_DefineNoEncoding_DefaultEncodingUsed()
Assert.Equal(sourceString, roundTrip);
}

[Fact]
public void Ctor_PassNullForMediaType_DefaultMediaTypeUsed()
{
string sourceString = "\u00C4\u00E4\u00FC\u00DC";
Encoding defaultStringEncoding = Encoding.GetEncoding("utf-8");
var content = new StringContent(sourceString, defaultStringEncoding, ((string)null)!);

// If no media is passed-in, the default is used
Assert.Equal("text/plain", content.Headers.ContentType.MediaType);
}

[Fact]
public async Task Ctor_UseCustomMediaTypeHeaderValue_SpecificEncoding()
{
Expand Down