Skip to content

Commit 215ac2f

Browse files
authored
Code cleanup in ContentHelper.Common.cs (PowerShell#18288)
1 parent ab7f206 commit 215ac2f

File tree

2 files changed

+4
-44
lines changed

2 files changed

+4
-44
lines changed

src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/ContentHelper.Common.cs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ namespace Microsoft.PowerShell.Commands
1313
{
1414
internal static class ContentHelper
1515
{
16-
#region Constants
17-
18-
// default codepage encoding for web content. See RFC 2616.
19-
private const string _defaultCodePage = "ISO-8859-1";
20-
21-
#endregion Constants
22-
23-
#region Fields
24-
25-
// used to split contentType arguments
26-
private static readonly char[] s_contentTypeParamSeparator = { ';' };
27-
28-
#endregion Fields
29-
3016
#region Internal Methods
3117

3218
internal static string GetContentType(HttpResponseMessage response)
@@ -37,33 +23,9 @@ internal static string GetContentType(HttpResponseMessage response)
3723

3824
internal static Encoding GetDefaultEncoding()
3925
{
40-
return GetEncodingOrDefault((string)null);
41-
}
42-
43-
internal static Encoding GetEncoding(HttpResponseMessage response)
44-
{
45-
// ContentType may not exist in response header.
46-
string charSet = response.Content.Headers.ContentType?.CharSet;
47-
return GetEncodingOrDefault(charSet);
48-
}
49-
50-
internal static Encoding GetEncodingOrDefault(string characterSet)
51-
{
52-
// get the name of the codepage to use for response content
53-
string codepage = (string.IsNullOrEmpty(characterSet) ? _defaultCodePage : characterSet);
54-
Encoding encoding = null;
55-
56-
try
57-
{
58-
encoding = Encoding.GetEncoding(codepage);
59-
}
60-
catch (ArgumentException)
61-
{
62-
// 0, default code page
63-
encoding = Encoding.GetEncoding(0);
64-
}
65-
66-
return encoding;
26+
// default codepage encoding for web content. See RFC 2616.
27+
Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
28+
return encoding;
6729
}
6830

6931
internal static StringBuilder GetRawContentHeader(HttpResponseMessage response)
@@ -206,7 +168,7 @@ private static string GetContentTypeSignature(string contentType)
206168
if (string.IsNullOrEmpty(contentType))
207169
return null;
208170

209-
string sig = contentType.Split(s_contentTypeParamSeparator, 2)[0].ToUpperInvariant();
171+
string sig = contentType.Split(';', 2)[0].ToUpperInvariant();
210172
return (sig);
211173
}
212174

src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,6 @@ internal override void ProcessResponse(HttpResponseMessage response)
404404
string charSet = response.Content.Headers.ContentType?.CharSet;
405405
if (!string.IsNullOrEmpty(charSet))
406406
{
407-
// NOTE: Don't use ContentHelper.GetEncoding; it returns a
408-
// default which bypasses checking for a meta charset value.
409407
StreamHelper.TryGetEncoding(charSet, out encoding);
410408
}
411409

0 commit comments

Comments
 (0)