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
18 changes: 17 additions & 1 deletion src/Microsoft.Graph.Core/Microsoft.Graph.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<AssemblyTitle>Microsoft Graph Core Client Library</AssemblyTitle>
<Authors>Microsoft</Authors>
<TargetFrameworks>netstandard1.1;net45;Xamarin.iOS10;MonoAndroid70</TargetFrameworks>
<TargetFrameworks>netstandard1.1;net45;Xamarin.iOS10;Xamarin.Mac20;MonoAndroid70</TargetFrameworks>
<PreserveCompilationContext>false</PreserveCompilationContext>
<AssemblyName>Microsoft.Graph.Core</AssemblyName>
<PackageId>Microsoft.Graph.Core</PackageId>
Expand Down Expand Up @@ -33,6 +33,13 @@
<DebugType>full</DebugType>
<LanguageTargets>$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets</LanguageTargets>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'Xamarin.Mac20'">
<TargetFrameworkIdentifier>Xamarin.Mac</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<DefineConstants>$(DefineConstants);macOS</DefineConstants>
<DebugType>full</DebugType>
<LanguageTargets>$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets</LanguageTargets>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'MonoAndroid70'">
<TargetFrameworkIdentifier>MonoAndroid</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v7.0</TargetFrameworkVersion>
Expand Down Expand Up @@ -77,6 +84,15 @@
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
<PackageReference Include="System.Net.Http" Version="4.3.3" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'Xamarin.Mac20' ">
<Reference Include="Xamarin.Mac" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
<PackageReference Include="System.Net.Http" Version="4.3.3" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'MonoAndroid70' ">
<Reference Include="Mono.Android" />
<Reference Include="System" />
Expand Down
13 changes: 10 additions & 3 deletions src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,20 @@ internal static (HttpMessageHandler Pipeline, FeatureFlag FeatureFlags) CreatePi
throw new ArgumentNullException(nameof(handlers), "DelegatingHandler array contains null item.");
}

#if iOS || macOS
#if iOS
// Skip CompressionHandler since NSUrlSessionHandler automatically handles decompression on iOS and it can't be turned off.
// Skip CompressionHandler since NSUrlSessionHandler automatically handles decompression on iOS and macOS and it can't be turned off.
// See issue https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/481 for more details.
if (finalHandler.GetType().Equals(typeof(NSUrlSessionHandler)) && handler.GetType().Equals(typeof(CompressionHandler)))
#elif macOS
if (finalHandler.GetType().Equals(typeof(Foundation.NSUrlSessionHandler)) && handler.GetType().Equals(typeof(CompressionHandler)))
#endif
{
// Skip chaining of CompressionHandler.
continue;
}
#endif

// Check for duplicate handler by type.
if (!existingHandlerTypes.Add(handler.GetType()))
{
Expand All @@ -206,18 +211,20 @@ internal static (HttpMessageHandler Pipeline, FeatureFlag FeatureFlags) CreatePi
}

/// <summary>
/// Gets a platform's native http handler i.e. NSUrlSessionHandler for Xamarin.iOS, AndroidClientHandler for Xamarin.Android and HttpClientHandler for others.
/// Gets a platform's native http handler i.e. NSUrlSessionHandler for Xamarin.iOS and Xamarin.Mac, AndroidClientHandler for Xamarin.Android and HttpClientHandler for others.
/// </summary>
/// <param name="proxy">The proxy to be used with created client.</param>
/// <returns>
/// 1. NSUrlSessionHandler for Xamarin.iOS
/// 1. NSUrlSessionHandler for Xamarin.iOS and Xamarin.Mac
/// 2. AndroidClientHandler for Xamarin.Android.
/// 3. HttpClientHandler for other platforms.
/// </returns>
internal static HttpMessageHandler GetNativePlatformHttpHandler(IWebProxy proxy = null)
{
#if iOS
return new NSUrlSessionHandler { AllowAutoRedirect = false };
#elif macOS
return new Foundation.NSUrlSessionHandler { AllowAutoRedirect = false };
#elif ANDROID
return new Xamarin.Android.Net.AndroidClientHandler { Proxy = proxy, AllowAutoRedirect = false, AutomaticDecompression = DecompressionMethods.None };
#else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;Xamarin.iOS10;MonoAndroid70</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;Xamarin.iOS10;Xamarin.Mac20;MonoAndroid70;</TargetFrameworks>
<AssemblyName>Microsoft.Graph.DotnetCore.Core.Test</AssemblyName>
<PackageId>Microsoft.Graph.DotnetCore.Core.Test</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
Expand All @@ -21,6 +21,14 @@
<DebugType>full</DebugType>
<LanguageTargets>$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets</LanguageTargets>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'Xamarin.Mac20'">
<TargetFrameworkIdentifier>Xamarin.Mac</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<DefineConstants>$(DefineConstants);macOS</DefineConstants>
<DebugType>full</DebugType>
<LanguageTargets>$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets</LanguageTargets>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'MonoAndroid70'">
<TargetFrameworkIdentifier>MonoAndroid</TargetFrameworkIdentifier>
Expand Down Expand Up @@ -58,6 +66,16 @@
<Reference Include="System.Runtime.Serialization" />
<PackageReference Include="System.Net.Http" Version="4.3.3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'Xamarin.Mac20' ">
<Reference Include="Microsoft.CSharp" />
<Reference Include="Xamarin.Mac" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="System.Runtime.Serialization" />
<PackageReference Include="System.Net.Http" Version="4.3.3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'MonoAndroid70' ">
<Reference Include="Microsoft.CSharp" />
Expand All @@ -69,7 +87,7 @@
<PackageReference Include="System.Net.Http" Version="4.3.3" />
</ItemGroup>

<ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ public void Dispose()
// and 'GraphClientFactory.DefaultHttpHandler' can easily be modified
// by other tests since it's a static delegate.

#if iOS
#if iOS || macOS
[Fact]
public void Should_CreatePipeline_Without_CompressionHandler()
{
using (AuthenticationHandler authenticationHandler = (AuthenticationHandler)GraphClientFactory.CreatePipeline(handlers))
using (RetryHandler retryHandler = (RetryHandler)authenticationHandler.InnerHandler)
using (RedirectHandler redirectHandler = (RedirectHandler)retryHandler.InnerHandler)
#if iOS
using (NSUrlSessionHandler innerMost = (NSUrlSessionHandler)redirectHandler.InnerHandler)
#elif macOS
using (Foundation.NSUrlSessionHandler innerMost = (Foundation.NSUrlSessionHandler)redirectHandler.InnerHandler)
#endif
{
Assert.NotNull(authenticationHandler);
Assert.NotNull(retryHandler);
Expand All @@ -57,7 +61,11 @@ public void Should_CreatePipeline_Without_CompressionHandler()
Assert.IsType<AuthenticationHandler>(authenticationHandler);
Assert.IsType<RetryHandler>(retryHandler);
Assert.IsType<RedirectHandler>(redirectHandler);
#if iOS
Assert.IsType<NSUrlSessionHandler>(innerMost);
#elif macOS
Assert.IsType<Foundation.NSUrlSessionHandler>(innerMost);
#endif
}
}
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public void HttpProvider_DefaultConstructor()
#elif iOS
Assert.IsType<NSUrlSessionHandler>(defaultHttpProvider.httpMessageHandler);
Assert.False((defaultHttpProvider.httpMessageHandler as NSUrlSessionHandler).AllowAutoRedirect);
#elif macOS
Assert.IsType<Foundation.NSUrlSessionHandler>(defaultHttpProvider.httpMessageHandler);
Assert.False((defaultHttpProvider.httpMessageHandler as Foundation.NSUrlSessionHandler).AllowAutoRedirect);
#else
Assert.IsType<HttpClientHandler>(defaultHttpProvider.httpMessageHandler);
Assert.False((defaultHttpProvider.httpMessageHandler as HttpClientHandler).AllowAutoRedirect);
Expand Down Expand Up @@ -554,12 +557,16 @@ public void HttpProvider_CustomAndroidClientHandler()
#endif
#endregion

#region iOS
#if iOS
#region iOS_macOS
#if iOS || macOS
[Fact]
public void HttpProvider_CustomNSUrlSessionHandler()
{
#if iOS
using (var httpClientHandler = new NSUrlSessionHandler())
#elif macOS
using (var httpClientHandler = new Foundation.NSUrlSessionHandler())
#endif
using (var httpProvider = new HttpProvider(httpClientHandler, false, null))
{
Assert.Equal(httpClientHandler, httpProvider.httpMessageHandler);
Expand All @@ -568,6 +575,6 @@ public void HttpProvider_CustomNSUrlSessionHandler()
}
}
#endif
#endregion
}
}
#endregion
}
}