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

[Enhancement] Add ability to be able to create both managed and native HttpCLient handlers in shared code #2028

Open
jgold6 opened this issue Aug 10, 2021 · 5 comments
Labels
area-core-hosting Extensions / Hosting / AppBuilder / Startup t/enhancement ☀️ New feature or request
Milestone

Comments

@jgold6
Copy link
Contributor

jgold6 commented Aug 10, 2021

Summary

In iOS and Android head projects, there is a project property setting to switch between using the managed HttpClient handlers and the native http client handlers for the platform, i.e. NSUrlSessionHandler (iOS) or AndroidClientHandler (Android).. In shared code if someone needs to add auth credentials, for instance for NTLM auth and wants to use the native handler (current managed HttpClientHandler on iOS has a bug that breaks NTLM auth), there is no way to create an HttpClient passing in a native handler without setting up a dependency service to create the HttpClient in the platform project such that a NSUrlSessionHandler/AndroidClientHandler can be passed in to the HttpClient constructor.

API Changes

Perhaps a FormsHttpClientHandler class can be created that would choose which http client handler to use based on the http client implementation selected in the iOS/Android project properties?

Intended Use Case

This would be useful to anyone who has to set properties on the HttpClientHandler before passing it into the HttpClient constructor, but wants to be able to do so from shared code and use whatever handler is set in the native project properties.

@AmrAlSayed0
Copy link
Contributor

I think .NET 6 is going to use the native HttpClientHandlers by default and there will be an option to use a flag (I think?) to switch to using the legacy managed one.

@jgold6
Copy link
Contributor Author

jgold6 commented Aug 11, 2021

So that would be the case even if someone explicitly passes a managed HttpClientHandler to the HttpClient constructor in the shared code base? It is sometimes required to add auth headers to the handler, and if you do that in shared code then you would not be able to create the native handler in shared code and would have to use a dependency service to create the native handler and pass it into the HttpClient ctor in the Android/iOS project.

@AmrAlSayed0
Copy link
Contributor

Yes, just doing new HttpClientHandler would automatically give you the native handler.
https://github.com/xamarin/xamarin-android/blob/main/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets#L12-L13
This change was made in Xamarin.Android (as a part of this commit) and I assume in Xamarin.iOS too

@jsuarezruiz jsuarezruiz added the t/enhancement ☀️ New feature or request label Oct 22, 2021
@jsuarezruiz jsuarezruiz added this to Under consideration in Enhancements Oct 22, 2021
@jfversluis jfversluis added the area-core-hosting Extensions / Hosting / AppBuilder / Startup label Aug 23, 2022
@jfversluis jfversluis added this to the Backlog milestone Aug 23, 2022
@ghost
Copy link

ghost commented Aug 23, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@muffadal53
Copy link

Also in my case we want to set following properties for Http calls. So, if HttpClient() uses native client handler in MAUI then please let me know how to do this in MAUI?

Set below properties to HttpClientHandler:

  • AllowAutoRedirect

  • MaxAutomaticRedirections

  • AutomaticDecompression

Awaiting feedback.

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-hosting Extensions / Hosting / AppBuilder / Startup t/enhancement ☀️ New feature or request
Projects
Enhancements
Under consideration
Development

No branches or pull requests

5 participants