From 77c622eeea474e21af0ea954836d49c53f71f5b1 Mon Sep 17 00:00:00 2001 From: Jonathan Malek Date: Fri, 2 Dec 2016 11:38:38 -0800 Subject: [PATCH] Wrapping a call to Registry so that Invoke-WebRequest does not fail on non-text responses (#2811) * Wrapping a call to Registry with a check for Platform.IsWindows --- .../utility/WebCmdlet/Common/ContentHelper.Common.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 def92d903..dc3a673ef 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 @@ -3,6 +3,7 @@ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ using System; +using System.Management.Automation; using System.Text; using Microsoft.Win32; @@ -87,7 +88,8 @@ namespace Microsoft.PowerShell.Commands || CheckIsXml(contentType) || CheckIsJson(contentType); - if (!isText) + // Further content type analysis is available on Windows + if (Platform.IsWindows && !isText) { // Media types registered with Windows as having a perceived type of text, are text using (RegistryKey contentTypeKey = Registry.ClassesRoot.OpenSubKey(@"MIME\Database\Content Type\" + contentType)) @@ -135,7 +137,7 @@ namespace Microsoft.PowerShell.Commands // the correct type for JSON content, as specified in RFC 4627 bool isJson = contentType.Equals("application/json", StringComparison.OrdinalIgnoreCase); - // add in these other "javascript" related types that + // add in these other "javascript" related types that // sometimes get sent down as the mime type for JSON content isJson |= contentType.Equals("text/json", StringComparison.OrdinalIgnoreCase) || contentType.Equals("application/x-javascript", StringComparison.OrdinalIgnoreCase)