Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/PowerShell/PowerShell.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarloToso <105941898+CarloToso@users.noreply.github.com>2022-10-25 00:52:09 +0300
committerGitHub <noreply@github.com>2022-10-25 00:52:09 +0300
commit215ac2f0f41789e6ee71d9ff1e3000b19c155b52 (patch)
treebb28ac67e3038479c30d42147a8cd761673e8c75
parentab7f2062717bfc3063c64e409706cb80ad8782f9 (diff)
Code cleanup in `ContentHelper.Common.cs` (#18288)
-rw-r--r--src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/ContentHelper.Common.cs46
-rw-r--r--src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs2
2 files changed, 4 insertions, 44 deletions
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/ContentHelper.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/ContentHelper.Common.cs
index f16ad99d2a..c7b8c878ca 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/ContentHelper.Common.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/ContentHelper.Common.cs
@@ -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);
}
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
index 0970ae46e8..72844df44f 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs
@@ -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);
}