Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 2 additions & 34 deletions src/Authentication/Authentication/Helpers/ContentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

using Microsoft.Graph.PowerShell.Authentication.Models;
using Microsoft.Win32;
using System;
using System.Globalization;
using System.Net.Http;
using System.Text;

using Microsoft.Graph.PowerShell.Authentication.Models;
using Microsoft.Win32;

namespace Microsoft.Graph.PowerShell.Authentication.Helpers
{
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
internal static RestReturnType CheckReturnType(this HttpResponseMessage response)
{
Expand Down Expand Up @@ -104,29 +95,6 @@ internal static string GetContentType(this HttpResponseMessage response)
return response.Content.Headers.ContentType?.MediaType;
}

internal static Encoding GetDefaultEncoding()
{
return GetEncodingOrDefault(null);
}

internal static Encoding GetEncodingOrDefault(string characterSet)
{
// get the name of the codepage to use for response content
var codepage = string.IsNullOrEmpty(characterSet) ? DefaultCodePage : characterSet;
Encoding encoding;
try
{
encoding = Encoding.GetEncoding(codepage);
}
catch (ArgumentException)
{
// 0, default code page
encoding = Encoding.GetEncoding(0);
}

return encoding;
}

internal static bool IsJson(string contentType)
{
contentType = GetContentTypeSignature(contentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ private void WaitOurTurn()
private void WaitForCompletion()
{
// wait for the result (or cancellation!)
WaitHandle.WaitAny(new[] {CancellationToken.WaitHandle, _completed?.WaitHandle});
WaitHandle.WaitAny(new[] { CancellationToken.WaitHandle, _completed?.WaitHandle });

// let go of the semaphore
_semaphore?.Release();
Expand Down
33 changes: 3 additions & 30 deletions src/Authentication/Authentication/Helpers/StreamHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

using Microsoft.Graph.PowerShell.Authentication.Cmdlets;
using Microsoft.Graph.PowerShell.Authentication.Properties;
using System;
using System.IO;
using System.Management.Automation;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Graph.PowerShell.Authentication.Cmdlets;
using Microsoft.Graph.PowerShell.Authentication.Properties;

namespace Microsoft.Graph.PowerShell.Authentication.Helpers
{
Expand All @@ -31,7 +31,7 @@ internal static byte[] EncodeToBytes(this string str, Encoding encoding)
if (encoding == null)
{
// just use the default encoding if one wasn't provided
encoding = ContentHelper.GetDefaultEncoding();
encoding = Encoding.UTF8;
}

return encoding.GetBytes(str);
Expand All @@ -43,33 +43,6 @@ internal static Stream GetResponseStream(this HttpResponseMessage response)
return responseStream;
}

internal static bool TryGetEncoding(this string characterSet, out Encoding encoding)
{
var result = false;
try
{
encoding = Encoding.GetEncoding(characterSet);
result = true;
}
catch (ArgumentException)
{
encoding = null;
}

return result;
}

internal static string DecodeStream(this BufferingStreamReader responseStream, ref Encoding encoding)
{
if (encoding == null)
{
// Use the default encoding if one wasn't provided
encoding = ContentHelper.GetDefaultEncoding();
}
var content = responseStream.StreamToString(encoding);
return content;
}

internal static string StreamToString(this Stream stream, Encoding encoding)
{
using (var reader = new StreamReader(stream, encoding))
Expand Down
8 changes: 3 additions & 5 deletions src/Authentication/Authentication/Helpers/StringUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------

using Microsoft.Graph.PowerShell.Authentication.Properties;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
Expand All @@ -12,11 +15,6 @@
using System.Text;
using System.Text.RegularExpressions;

using Microsoft.Graph.PowerShell.Authentication.Properties;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.Graph.PowerShell.Authentication.Helpers
{
public static class StringUtil
Expand Down