mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Code cleanup in ContentHelper.Common.cs (#18288)
This commit is contained in:
+4
-42
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
-2
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user