Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native HTTP client handlers for Xamarin.iOS and Xamarin.Android #481

Closed
peombwa opened this issue May 24, 2019 · 1 comment
Closed
Assignees

Comments

@peombwa
Copy link
Member

peombwa commented May 24, 2019

Issue

Due to HttpClientHandler's limitations described in issues #413, we need to configure our pipeline to use optimized native Http handlers for Xamarin.Android (AndroidClientHandler) and Xamarin.iOS (NSUrlSessionHandler) as our final handler.

Workaround

The workaround involves setting up a new pipeline for each platform with the platforms native http handler set as the finalHandler. This is cumbersome and can be error prone if not configured correctly.

#if __ANDROID__
            var innerHandler = new Xamarin.Android.Net.AndroidClientHandler { AllowAutoRedirect = false };
            var pipeline = GraphClientFactory.CreatePipeline(GraphClientFactory.CreateDefaultHandlers(authProvider), innerHandler);
            httpProvider = new HttpProvider(pipeline, true, new Serializer());
#elif __IOS__
            var innerHandler = new NSUrlSessionHandler { AllowAutoRedirect = false };
            var handlers = GraphClientFactory.CreateDefaultHandlers(authProvider);
            // Remove CompressionHandler from pipeline when using NSUrlSessionHandler.
            handlers.Remove(handlers.FirstOrDefault((h) => h.GetType().Equals(typeof(CompressionHandler)))); // We need to provide a method to remove handlers by type. 
            var pipeline = GraphClientFactory.CreatePipeline(handlers , innerHandler);
            httpProvider = new HttpProvider(pipeline, true, new Serializer());
#else // UWP
            httpProvider = new HttpProvider();
#endif
            return new GraphServiceClient(authProvider, httpProvider);
@peombwa
Copy link
Member Author

peombwa commented Jun 19, 2019

@peombwa peombwa closed this as completed Jun 19, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Feb 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant