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 41af8ebc6dc..bf127967ffe 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 @@ -60,28 +60,6 @@ internal static StringBuilder GetRawContentHeader(HttpResponseMessage response) } internal static bool IsJson(string contentType) - { - contentType = GetContentTypeSignature(contentType); - return CheckIsJson(contentType); - } - - internal static bool IsText(string contentType) - { - contentType = GetContentTypeSignature(contentType); - return CheckIsText(contentType); - } - - internal static bool IsXml(string contentType) - { - contentType = GetContentTypeSignature(contentType); - return CheckIsXml(contentType); - } - - #endregion Internal Methods - - #region Private Helper Methods - - private static bool CheckIsJson(string contentType) { if (string.IsNullOrEmpty(contentType)) { @@ -102,7 +80,7 @@ private static bool CheckIsJson(string contentType) return isJson; } - private static bool CheckIsText(string contentType) + internal static bool IsText(string contentType) { if (string.IsNullOrEmpty(contentType)) { @@ -111,8 +89,8 @@ private static bool CheckIsText(string contentType) // Any text, xml or json types are text bool isText = contentType.StartsWith("text/", StringComparison.OrdinalIgnoreCase) - || CheckIsXml(contentType) - || CheckIsJson(contentType); + || IsXml(contentType) + || IsJson(contentType); // Further content type analysis is available on Windows if (Platform.IsWindows && !isText) @@ -141,7 +119,7 @@ private static bool CheckIsText(string contentType) return isText; } - private static bool CheckIsXml(string contentType) + internal static bool IsXml(string contentType) { if (string.IsNullOrEmpty(contentType)) { @@ -157,17 +135,6 @@ private static bool CheckIsXml(string contentType) return isXml; } - private static string GetContentTypeSignature(string contentType) - { - if (string.IsNullOrEmpty(contentType)) - { - return null; - } - - string sig = contentType.Split(';', 2)[0].ToUpperInvariant(); - return sig; - } - - #endregion Private Helper Methods + #endregion Internal Methods } } diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs index 1ddaf5a5794..49cc7d43402 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs @@ -383,13 +383,7 @@ private static string StreamToString(Stream stream, Encoding encoding) internal static string DecodeStream(Stream stream, string characterSet, out Encoding encoding) { - bool isDefaultEncoding = false; - if (!TryGetEncoding(characterSet, out encoding)) - { - // Use the default encoding if one wasn't provided - encoding = ContentHelper.GetDefaultEncoding(); - isDefaultEncoding = true; - } + bool isDefaultEncoding = !TryGetEncoding(characterSet, out encoding); string content = StreamToString(stream, encoding); if (isDefaultEncoding) @@ -433,7 +427,8 @@ internal static bool TryGetEncoding(string characterSet, out Encoding encoding) } catch (ArgumentException) { - encoding = null; + // Use the default encoding if one wasn't provided + encoding = ContentHelper.GetDefaultEncoding(); } return result;