Code cleanup in ContentHelper.Common.cs (#18288)

This commit is contained in:
CarloToso
2022-10-24 14:52:09 -07:00
committed by GitHub
parent ab7f206271
commit 215ac2f0f4
2 changed files with 4 additions and 44 deletions
@@ -13,20 +13,6 @@ namespace Microsoft.PowerShell.Commands
{
internal static class ContentHelper
{
#region Constants
// default codepage encoding for web content. See RFC 2616.
private const string _defaultCodePage = "ISO-8859-1";
#endregion Constants
#region Fields
// used to split contentType arguments
private static readonly char[] s_contentTypeParamSeparator = { ';' };
#endregion Fields
#region Internal Methods
internal static string GetContentType(HttpResponseMessage response)
@@ -37,33 +23,9 @@ namespace Microsoft.PowerShell.Commands
internal static Encoding GetDefaultEncoding()
{
return GetEncodingOrDefault((string)null);
}
internal static Encoding GetEncoding(HttpResponseMessage response)
{
// ContentType may not exist in response header.
string charSet = response.Content.Headers.ContentType?.CharSet;
return GetEncodingOrDefault(charSet);
}
internal static Encoding GetEncodingOrDefault(string characterSet)
{
// get the name of the codepage to use for response content
string codepage = (string.IsNullOrEmpty(characterSet) ? _defaultCodePage : characterSet);
Encoding encoding = null;
try
{
encoding = Encoding.GetEncoding(codepage);
}
catch (ArgumentException)
{
// 0, default code page
encoding = Encoding.GetEncoding(0);
}
return encoding;
// default codepage encoding for web content. See RFC 2616.
Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
return encoding;
}
internal static StringBuilder GetRawContentHeader(HttpResponseMessage response)
@@ -206,7 +168,7 @@ namespace Microsoft.PowerShell.Commands
if (string.IsNullOrEmpty(contentType))
return null;
string sig = contentType.Split(s_contentTypeParamSeparator, 2)[0].ToUpperInvariant();
string sig = contentType.Split(';', 2)[0].ToUpperInvariant();
return (sig);
}
@@ -404,8 +404,6 @@ namespace Microsoft.PowerShell.Commands
string charSet = response.Content.Headers.ContentType?.CharSet;
if (!string.IsNullOrEmpty(charSet))
{
// NOTE: Don't use ContentHelper.GetEncoding; it returns a
// default which bypasses checking for a meta charset value.
StreamHelper.TryGetEncoding(charSet, out encoding);
}