xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.46k stars 511 forks source link

Support for Proxy in HttpClient in iOS #18635

Open rolfbjarne opened 1 year ago

rolfbjarne commented 1 year ago

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

Screenshot 2023-05-19 at 14 15 50

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

rolfbjarne commented 1 year ago

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?

Syed-RI commented 1 year ago

Glad to see that the issue is getting a bit of attention! ❤️

M4ttsson commented 1 year ago

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

rolfbjarne commented 1 year ago

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:

Axemasta commented 9 months ago

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?

rolfbjarne commented 9 months ago

@Axemasta no news yet, but we're trying to have a look at this in the .NET 9 time frame (no promises though).