xamarin-macios
xamarin-macios copied to clipboard
Support for Proxy in HttpClient in iOS
From @Syed-RI on Fri, 19 May 2023 13:23:03 GMT
Description
Please provide support/implementations to enable proxy in iOS
We are currently working on some enterprise applications which will be deployed to corporate devices via their MDM systems and they will enforce proxy on these devices. I was horrified seeing this bit of warning in my .NET MAUI app
Bit of search revealed more horrors here: https://github.com/xamarin/xamarin-macios/issues/14632
May be this is bit late for our project and we will have to abstract and have platform specific, unmanaged HttpClientHandlers to support proxy in iOS devices. Is there any proposal anywhere or official workaround? Apologies, if there is any and I have somehow missed it.
CC @davidortinau @PureWeen @Redth @rolfbjarne for visibility
Public API Changes
NONE
Intended Use-Case
To support and enable proxy in IHttpClientFactory for iOS devices
Copied from original issue dotnet/maui#15179
From @Eilon on Thu, 03 Aug 2023 21:03:20 GMT
@rolfbjarne - does this seem like it should move to xamarin-macios or dotnet/runtime?
Glad to see that the issue is getting a bit of attention! ❤️
Hi, just ran into this problem when migrating away from an old Xamarin project.
Since Proxy settings is not supported (anymore?), what would be the default behavior on iOS if not setting the proxy by code? Would the app respect any proxy from the system settings on the device, or try to go directly bypassing the proxy?
If bypassing, is there any workarounds to this since waiting until .NET 9 is not an option due to Xamarin EOL..
Thanks
Hi, just ran into this problem when migrating away from an old Xamarin project.
Since Proxy settings is not supported (anymore?), what would be the default behavior on iOS if not setting the proxy by code? Would the app respect any proxy from the system settings on the device, or try to go directly bypassing the proxy?
If bypassing, is there any workarounds to this since waiting until .NET 9 is not an option due to Xamarin EOL..
Thanks
Yes, it will use the system proxy settings.
You might also be able to use the .NET http handler instead of the native one, by setting this in your csproj:
<PropertyGroup>
<UseNativeHttpHandler>false</UseNativeHttpHandler>
</PropertyGroup>
There are a few downsides:
- This will not use the system proxy (the app itself doesn't have access to the system proxy settings (in particular any passwords), so the .NET http handler doesn't either).
- Battery usage may be higher.
- Any network requests may be delayed/fail if the device is not connected to WiFi and the networking stack is sleeping because the .NET http handler won't wake the networking stack up again (https://learn.microsoft.com/en-us/dotnet/api/objcruntime.runtime.startwwan?view=xamarin-ios-sdk-12 is the fix for this).
Now maui is in a relatively stable place, will there be support for this natively without the workaround described?
Using a proxy is important to an app I am working on and I dont want to lose the advantages of the native platform (there will be device proxies setup for example). Any idea of when this change would come into effect?
@Axemasta no news yet, but we're trying to have a look at this in the .NET 9 time frame (no promises though).