From 57dd919ab81e8914b1c4ef63c4f8ee55bc79c347 Mon Sep 17 00:00:00 2001 From: Steve Pfister Date: Tue, 17 Aug 2021 10:52:51 -0400 Subject: [PATCH] [iOS] [Android] Remove PNSE from some HttpClientHandler methods (#57555) Since HttpClientHandler on mobile can support both the underlying native handler and SocketsHttpHandler, it doesn't make sense to always throw PNSE on some methods due to only the native handler not supporting them. Fixes https://github.com/dotnet/runtime/issues/55986 Co-authored-by: Steve Pfister --- .../System.Net.Http/ref/System.Net.Http.cs | 40 -- .../ILLink/ILLink.Suppressions.LibraryBuild.xml | 119 ++++++ .../System.Net.Http/src/System.Net.Http.csproj | 2 - .../System/Net/Http/HttpClientHandler.Android.cs | 192 +++------ .../System/Net/Http/HttpClientHandler.AnyMobile.cs | 459 ++++++++++++++++++--- .../src/System/Net/Http/HttpClientHandler.Apple.cs | 60 --- .../Net/Http/HttpClientHandler.MacCatalyst.cs | 85 ++++ .../src/System/Net/Http/HttpClientHandler.cs | 38 -- .../src/System/Net/Http/HttpClientHandler.iOS.cs | 85 ++++ .../src/System/Net/Http/HttpClientHandler.tvOS.cs | 85 ++++ 10 files changed, 834 insertions(+), 331 deletions(-) delete mode 100644 src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.Apple.cs diff --git a/src/libraries/System.Net.Http/ref/System.Net.Http.cs b/src/libraries/System.Net.Http/ref/System.Net.Http.cs index 6e16280..0f63c2b 100644 --- a/src/libraries/System.Net.Http/ref/System.Net.Http.cs +++ b/src/libraries/System.Net.Http/ref/System.Net.Http.cs @@ -114,73 +114,35 @@ namespace System.Net.Http public HttpClientHandler() { } public bool AllowAutoRedirect { get { throw null; } set { } } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public System.Net.DecompressionMethods AutomaticDecompression { get { throw null; } set { } } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public bool CheckCertificateRevocationList { get { throw null; } set { } } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public System.Net.Http.ClientCertificateOption ClientCertificateOptions { get { throw null; } set { } } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public System.Security.Cryptography.X509Certificates.X509CertificateCollection ClientCertificates { get { throw null; } } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Net.CookieContainer CookieContainer { get { throw null; } set { } } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Net.ICredentials? Credentials { get { throw null; } set { } } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public static System.Func DangerousAcceptAnyServerCertificateValidator { get { throw null; } } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public System.Net.ICredentials? DefaultProxyCredentials { get { throw null; } set { } } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public int MaxAutomaticRedirections { get { throw null; } set { } } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public int MaxConnectionsPerServer { get { throw null; } set { } } public long MaxRequestContentBufferSize { get { throw null; } set { } } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public int MaxResponseHeadersLength { get { throw null; } set { } } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public bool PreAuthenticate { get { throw null; } set { } } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public System.Collections.Generic.IDictionary Properties { get { throw null; } } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public System.Net.IWebProxy? Proxy { get { throw null; } set { } } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public System.Func? ServerCertificateCustomValidationCallback { get { throw null; } set { } } - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("android")] [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public System.Security.Authentication.SslProtocols SslProtocols { get { throw null; } set { } } public virtual bool SupportsAutomaticDecompression { get { throw null; } } public virtual bool SupportsProxy { get { throw null; } } @@ -190,8 +152,6 @@ namespace System.Net.Http [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool UseDefaultCredentials { get { throw null; } set { } } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public bool UseProxy { get { throw null; } set { } } protected override void Dispose(bool disposing) { } // diff --git a/src/libraries/System.Net.Http/src/ILLink/ILLink.Suppressions.LibraryBuild.xml b/src/libraries/System.Net.Http/src/ILLink/ILLink.Suppressions.LibraryBuild.xml index dbeca2a..a6af29a 100644 --- a/src/libraries/System.Net.Http/src/ILLink/ILLink.Suppressions.LibraryBuild.xml +++ b/src/libraries/System.Net.Http/src/ILLink/ILLink.Suppressions.LibraryBuild.xml @@ -141,5 +141,124 @@ M:System.Net.Http.HttpClientHandler.SetMaxAutomaticRedirections(System.Int32) The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.GetCheckCertificateRevocationList() + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.SetCheckCertificateRevocationList(System.Boolean) + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.GetClientCertificateOptions() + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.SetClientCertificateOptions(System.Net.Http.ClientCertificateOption) + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.GetClientCertificates() + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.GetDefaultProxyCredentials() + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.SetDefaultProxyCredentials(System.Net.ICredentials) + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.GetMaxConnectionsPerServer() + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.SetMaxConnectionsPerServer(System.Int32) + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.GetMaxResponseHeadersLength() + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.SetMaxResponseHeadersLength(System.Int32) + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.GetProperties() + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.GetSupportsAutomaticDecompression() + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.GetSupportsProxy() + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.GetSupportsRedirectConfiguration() + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.GetSslProtocols() + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + + + ILLink + IL2035 + member + M:System.Net.Http.HttpClientHandler.SetSslProtocols(System.Security.Authentication.SslProtocols) + The Xamarin.iOS and Mono.Android libraries are not present when running the trimmer analysis during our build. A consuming application will get a warning if these libraries aren't present when trimming the full app. + diff --git a/src/libraries/System.Net.Http/src/System.Net.Http.csproj b/src/libraries/System.Net.Http/src/System.Net.Http.csproj index be74272..28de4bb 100644 --- a/src/libraries/System.Net.Http/src/System.Net.Http.csproj +++ b/src/libraries/System.Net.Http/src/System.Net.Http.csproj @@ -41,8 +41,6 @@ - diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.Android.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.Android.cs index a87a044..95face9 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.Android.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.Android.cs @@ -2,9 +2,13 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Net.Security; using System.Reflection; using System.Runtime.Versioning; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; namespace System.Net.Http { @@ -15,154 +19,56 @@ namespace System.Net.Http private const string NativeHandlerType = "Xamarin.Android.Net.AndroidMessageHandler"; private const string AssemblyName = "Mono.Android"; - public virtual bool SupportsAutomaticDecompression => true; - public virtual bool SupportsProxy => true; - public virtual bool SupportsRedirectConfiguration => true; + [DynamicDependency("get_DefaultProxyCredentials", NativeHandlerType, AssemblyName)] + private ICredentials? GetDefaultProxyCredentials() => (ICredentials?)InvokeNativeHandlerMethod("get_DefaultProxyCredentials"); - [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public DecompressionMethods AutomaticDecompression - { - get - { - if (IsNativeHandlerEnabled) - { - return GetAutomaticDecompression(); - } - else - { - return _socketHandler!.AutomaticDecompression; - } - } - set - { - if (IsNativeHandlerEnabled) - { - SetAutomaticDecompression(value); - } - else - { - _socketHandler!.AutomaticDecompression = value; - } - } - } + [DynamicDependency("set_DefaultProxyCredentials", NativeHandlerType, AssemblyName)] + private void SetDefaultProxyCredentials(ICredentials? value) => InvokeNativeHandlerMethod("set_DefaultProxyCredentials", value); - [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public bool UseProxy - { - get - { - if (IsNativeHandlerEnabled) - { - return GetUseProxy(); - } - else - { - return _socketHandler!.UseProxy; - } - } - set - { - if (IsNativeHandlerEnabled) - { - SetUseProxy(value); - } - else - { - _socketHandler!.UseProxy = value; - } - } - } + [DynamicDependency("get_MaxConnectionsPerServer", NativeHandlerType, AssemblyName)] + private int GetMaxConnectionsPerServer() => (int)InvokeNativeHandlerMethod("get_MaxConnectionsPerServer"); - [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public IWebProxy? Proxy - { - get - { - if (IsNativeHandlerEnabled) - { - return GetProxy(); - } - else - { - return _socketHandler!.Proxy; - } - } - set - { - if (IsNativeHandlerEnabled) - { - SetProxy(value!); - } - else - { - _socketHandler!.Proxy = value; - } - } - } + [DynamicDependency("set_MaxConnectionsPerServer", NativeHandlerType, AssemblyName)] + private void SetMaxConnectionsPerServer(int value) => InvokeNativeHandlerMethod("set_MaxConnectionsPerServer", value); - [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public bool PreAuthenticate - { - get - { - if (IsNativeHandlerEnabled) - { - return GetPreAuthenticate(); - } - else - { - return _socketHandler!.PreAuthenticate; - } - } - set - { - if (IsNativeHandlerEnabled) - { - SetPreAuthenticate(value); - } - else - { - _socketHandler!.PreAuthenticate = value; - } - } - } + [DynamicDependency("get_MaxResponseHeadersLength", NativeHandlerType, AssemblyName)] + private int GetMaxResponseHeadersLength() => (int)InvokeNativeHandlerMethod("get_MaxResponseHeadersLength"); - [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public int MaxAutomaticRedirections - { - get - { - if (IsNativeHandlerEnabled) - { - return GetMaxAutomaticRedirections(); - } - else - { - return _socketHandler!.MaxAutomaticRedirections; - } - } - set - { - if (IsNativeHandlerEnabled) - { - SetMaxAutomaticRedirections(value); - } - else - { - _socketHandler!.MaxAutomaticRedirections = value; - } - } - } + [DynamicDependency("set_MaxResponseHeadersLength", NativeHandlerType, AssemblyName)] + private void SetMaxResponseHeadersLength(int value) => InvokeNativeHandlerMethod("set_MaxResponseHeadersLength", value); + + [DynamicDependency("get_ClientCertificateOptions", NativeHandlerType, AssemblyName)] + private ClientCertificateOption GetClientCertificateOptions() => (ClientCertificateOption)InvokeNativeHandlerMethod("get_ClientCertificateOptions"); + + [DynamicDependency("set_ClientCertificateOptions", NativeHandlerType, AssemblyName)] + private void SetClientCertificateOptions(ClientCertificateOption value) => InvokeNativeHandlerMethod("set_ClientCertificateOptions", value); + + [DynamicDependency("get_ClientCertificates", NativeHandlerType, AssemblyName)] + private X509CertificateCollection GetClientCertificates() => (X509CertificateCollection)InvokeNativeHandlerMethod("get_ClientCertificates"); + + [DynamicDependency("get_CheckCertificateRevocationList", NativeHandlerType, AssemblyName)] + private bool GetCheckCertificateRevocationList() => (bool)InvokeNativeHandlerMethod("get_CheckCertificateRevocationList"); + + [DynamicDependency("set_CheckCertificateRevocationList", NativeHandlerType, AssemblyName)] + private void SetCheckCertificateRevocationList(bool value) => InvokeNativeHandlerMethod("set_CheckCertificateRevocationList", value); + + [DynamicDependency("get_SslProtocols", NativeHandlerType, AssemblyName)] + private SslProtocols GetSslProtocols() => (SslProtocols)InvokeNativeHandlerMethod("get_SslProtocols"); + + [DynamicDependency("set_SslProtocols", NativeHandlerType, AssemblyName)] + private void SetSslProtocols(SslProtocols value) => InvokeNativeHandlerMethod("set_SslProtocols", value); + + [DynamicDependency("get_Properties", NativeHandlerType, AssemblyName)] + private IDictionary GetProperties() => (IDictionary)InvokeNativeHandlerMethod("get_Properties"); + + [DynamicDependency("get_SupportsAutomaticDecompression", NativeHandlerType, AssemblyName)] + private bool GetSupportsAutomaticDecompression() => (bool)InvokeNativeHandlerMethod("get_SupportsAutomaticDecompression"); + + [DynamicDependency("get_SupportsProxy", NativeHandlerType, AssemblyName)] + private bool GetSupportsProxy() => (bool)InvokeNativeHandlerMethod("get_SupportsProxy"); + + [DynamicDependency("get_SupportsRedirectConfiguration", NativeHandlerType, AssemblyName)] + private bool GetSupportsRedirectConfiguration() => (bool)InvokeNativeHandlerMethod("get_SupportsRedirectConfiguration"); [DynamicDependency("get_MaxAutomaticRedirections", NativeHandlerType, AssemblyName)] private int GetMaxAutomaticRedirections() => (int)InvokeNativeHandlerMethod("get_MaxAutomaticRedirections"); diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.cs index 63f68ee..e6168b4 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.AnyMobile.cs @@ -28,6 +28,8 @@ namespace System.Net.Http private static readonly ConcurrentDictionary s_cachedMethods = new ConcurrentDictionary(); + private ClientCertificateOption _clientCertificateOptions; + private volatile bool _disposed; public HttpClientHandler() @@ -43,6 +45,7 @@ namespace System.Net.Http { _socketHandler = new SocketsHttpHandler(); handler = _socketHandler; + ClientCertificateOptions = ClientCertificateOption.Manual; } if (DiagnosticsHandler.IsGloballyEnabled()) @@ -129,14 +132,31 @@ namespace System.Net.Http } } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public ICredentials? DefaultProxyCredentials { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); + get + { + if (IsNativeHandlerEnabled) + { + return GetDefaultProxyCredentials(); + } + else + { + return _socketHandler!.DefaultProxyCredentials; + } + } + set + { + if (IsNativeHandlerEnabled) + { + SetDefaultProxyCredentials(value); + } + else + { + _socketHandler!.DefaultProxyCredentials = value; + } + } } [UnsupportedOSPlatform("browser")] @@ -248,14 +268,31 @@ namespace System.Net.Http } } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public int MaxConnectionsPerServer { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); + get + { + if (IsNativeHandlerEnabled) + { + return GetMaxConnectionsPerServer(); + } + else + { + return _socketHandler!.MaxConnectionsPerServer; + } + } + set + { + if (IsNativeHandlerEnabled) + { + SetMaxConnectionsPerServer(value); + } + else + { + _socketHandler!.MaxConnectionsPerServer = value; + } + } } public long MaxRequestContentBufferSize @@ -291,71 +328,377 @@ namespace System.Net.Http } } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public int MaxResponseHeadersLength { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); + get + { + if (IsNativeHandlerEnabled) + { + return GetMaxResponseHeadersLength(); + } + else + { + return _socketHandler!.MaxResponseHeadersLength; + } + } + set + { + if (IsNativeHandlerEnabled) + { + SetMaxResponseHeadersLength(value); + } + else + { + _socketHandler!.MaxResponseHeadersLength = value; + } + } } - [UnsupportedOSPlatform("android")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public ClientCertificateOption ClientCertificateOptions { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); + get + { + if (IsNativeHandlerEnabled) + { + return GetClientCertificateOptions(); + } + else + { + return _clientCertificateOptions; + } + } + set + { + if (IsNativeHandlerEnabled) + { + SetClientCertificateOptions(value); + } + else + { + switch (value) + { + case ClientCertificateOption.Manual: + ThrowForModifiedManagedSslOptionsIfStarted(); + _clientCertificateOptions = value; + _socketHandler!.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate(ClientCertificates)!; + break; + + case ClientCertificateOption.Automatic: + ThrowForModifiedManagedSslOptionsIfStarted(); + _clientCertificateOptions = value; + _socketHandler!.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate()!; + break; + + default: + throw new ArgumentOutOfRangeException(nameof(value)); + } + } + } } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public X509CertificateCollection ClientCertificates { get { - throw new PlatformNotSupportedException(); + if (IsNativeHandlerEnabled) + { + return GetClientCertificates(); + } + else + { + if (ClientCertificateOptions != ClientCertificateOption.Manual) + { + throw new InvalidOperationException(SR.Format(SR.net_http_invalid_enable_first, nameof(ClientCertificateOptions), nameof(ClientCertificateOption.Manual))); + } + + return _socketHandler!.SslOptions.ClientCertificates ?? + (_socketHandler!.SslOptions.ClientCertificates = new X509CertificateCollection()); + } } } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public Func? ServerCertificateCustomValidationCallback { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); + get + { + if (IsNativeHandlerEnabled) + { + throw new PlatformNotSupportedException(); + } + else + { + return (_socketHandler!.SslOptions.RemoteCertificateValidationCallback?.Target as ConnectHelper.CertificateCallbackMapper)?.FromHttpClientHandler; + } + } + set + { + if (IsNativeHandlerEnabled) + { + throw new PlatformNotSupportedException(); + } + else + { + ThrowForModifiedManagedSslOptionsIfStarted(); + _socketHandler!.SslOptions.RemoteCertificateValidationCallback = value != null ? + new ConnectHelper.CertificateCallbackMapper(value).ForSocketsHttpHandler : + null; + } + } } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public bool CheckCertificateRevocationList { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); + get + { + if (IsNativeHandlerEnabled) + { + return GetCheckCertificateRevocationList(); + } + else + { + return _socketHandler!.SslOptions.CertificateRevocationCheckMode == X509RevocationMode.Online; + } + } + set + { + if (IsNativeHandlerEnabled) + { + SetCheckCertificateRevocationList(value); + } + else + { + ThrowForModifiedManagedSslOptionsIfStarted(); + _socketHandler!.SslOptions.CertificateRevocationCheckMode = value ? X509RevocationMode.Online : X509RevocationMode.NoCheck; + } + } } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public SslProtocols SslProtocols { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); + get + { + if (IsNativeHandlerEnabled) + { + return GetSslProtocols(); + } + else + { + return _socketHandler!.SslOptions.EnabledSslProtocols; + } + } + set + { + if (IsNativeHandlerEnabled) + { + SetSslProtocols(value); + } + else + { + ThrowForModifiedManagedSslOptionsIfStarted(); + _socketHandler!.SslOptions.EnabledSslProtocols = value; + } + } + } + + public IDictionary Properties + { + get + { + if (IsNativeHandlerEnabled) + { + return GetProperties(); + } + else + { + return _socketHandler!.Properties; + } + } + } + + public virtual bool SupportsAutomaticDecompression + { + get + { + if (IsNativeHandlerEnabled) + { + return GetSupportsAutomaticDecompression(); + } + else + { + return SocketsHttpHandler.SupportsAutomaticDecompression; + } + } + } + + public virtual bool SupportsProxy + { + get + { + if (IsNativeHandlerEnabled) + { + return GetSupportsProxy(); + } + else + { + return SocketsHttpHandler.SupportsProxy; + } + } + } + + public virtual bool SupportsRedirectConfiguration + { + get + { + if (IsNativeHandlerEnabled) + { + return GetSupportsRedirectConfiguration(); + } + else + { + return SocketsHttpHandler.SupportsRedirectConfiguration; + } + } + } + + [UnsupportedOSPlatform("browser")] + public DecompressionMethods AutomaticDecompression + { + get + { + if (IsNativeHandlerEnabled) + { + return GetAutomaticDecompression(); + } + else + { + return _socketHandler!.AutomaticDecompression; + } + } + set + { + if (IsNativeHandlerEnabled) + { + SetAutomaticDecompression(value); + } + else + { + _socketHandler!.AutomaticDecompression = value; + } + } } - [UnsupportedOSPlatform("android")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public IDictionary Properties => throw new PlatformNotSupportedException(); + [UnsupportedOSPlatform("browser")] + public bool UseProxy + { + get + { + if (IsNativeHandlerEnabled) + { + return GetUseProxy(); + } + else + { + return _socketHandler!.UseProxy; + } + } + set + { + if (IsNativeHandlerEnabled) + { + SetUseProxy(value); + } + else + { + _socketHandler!.UseProxy = value; + } + } + } + + [UnsupportedOSPlatform("browser")] + public IWebProxy? Proxy + { + get + { + if (IsNativeHandlerEnabled) + { + return GetProxy(); + } + else + { + return _socketHandler!.Proxy; + } + } + set + { + if (IsNativeHandlerEnabled) + { + SetProxy(value!); + } + else + { + _socketHandler!.Proxy = value; + } + } + } + + [UnsupportedOSPlatform("browser")] + public bool PreAuthenticate + { + get + { + if (IsNativeHandlerEnabled) + { + return GetPreAuthenticate(); + } + else + { + return _socketHandler!.PreAuthenticate; + } + } + set + { + if (IsNativeHandlerEnabled) + { + SetPreAuthenticate(value); + } + else + { + _socketHandler!.PreAuthenticate = value; + } + } + } + + [UnsupportedOSPlatform("browser")] + public int MaxAutomaticRedirections + { + get + { + if (IsNativeHandlerEnabled) + { + return GetMaxAutomaticRedirections(); + } + else + { + return _socketHandler!.MaxAutomaticRedirections; + } + } + set + { + if (IsNativeHandlerEnabled) + { + SetMaxAutomaticRedirections(value); + } + else + { + _socketHandler!.MaxAutomaticRedirections = value; + } + } + } // // Attributes are commented out due to https://github.com/dotnet/arcade/issues/7585 @@ -389,12 +732,32 @@ namespace System.Net.Http } } - [UnsupportedOSPlatform("android")] + // lazy-load the validator func so it can be trimmed by the ILLinker if it isn't used. + private static Func? s_dangerousAcceptAnyServerCertificateValidator; [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public static Func DangerousAcceptAnyServerCertificateValidator => - throw new PlatformNotSupportedException(); + public static Func DangerousAcceptAnyServerCertificateValidator + { + get + { + if (IsNativeHandlerEnabled) + { + throw new PlatformNotSupportedException(); + } + else + { + return Volatile.Read(ref s_dangerousAcceptAnyServerCertificateValidator) ?? + Interlocked.CompareExchange(ref s_dangerousAcceptAnyServerCertificateValidator, delegate { return true; }, null) ?? + s_dangerousAcceptAnyServerCertificateValidator; + } + } + } + + private void ThrowForModifiedManagedSslOptionsIfStarted() + { + // Hack to trigger an InvalidOperationException if a property that's stored on + // SslOptions is changed, since SslOptions itself does not do any such checks. + _socketHandler!.SslOptions = _socketHandler!.SslOptions; + } private void CheckDisposed() { diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.Apple.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.Apple.cs deleted file mode 100644 index b6c8ce9..0000000 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.Apple.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Runtime.Versioning; - -namespace System.Net.Http -{ - public partial class HttpClientHandler : HttpMessageHandler - { - public virtual bool SupportsAutomaticDecompression => false; - public virtual bool SupportsProxy => false; - public virtual bool SupportsRedirectConfiguration => true; - - [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public DecompressionMethods AutomaticDecompression - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public bool UseProxy - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public IWebProxy? Proxy - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public int MaxAutomaticRedirections - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - - [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] - public bool PreAuthenticate - { - get => throw new PlatformNotSupportedException(); - set => throw new PlatformNotSupportedException(); - } - } -} diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.MacCatalyst.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.MacCatalyst.cs index 886e9cd..182c6b0 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.MacCatalyst.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.MacCatalyst.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Net.Security; using System.Reflection; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; namespace System.Net.Http { @@ -14,6 +18,87 @@ namespace System.Net.Http private const string NativeHandlerType = "System.Net.Http.NSUrlSessionHandler"; private const string AssemblyName = "Xamarin.MacCatalyst"; + [DynamicDependency("get_DefaultProxyCredentials", NativeHandlerType, AssemblyName)] + private ICredentials? GetDefaultProxyCredentials() => (ICredentials?)InvokeNativeHandlerMethod("get_DefaultProxyCredentials"); + + [DynamicDependency("set_DefaultProxyCredentials", NativeHandlerType, AssemblyName)] + private void SetDefaultProxyCredentials(ICredentials? value) => InvokeNativeHandlerMethod("set_DefaultProxyCredentials", value); + + [DynamicDependency("get_MaxConnectionsPerServer", NativeHandlerType, AssemblyName)] + private int GetMaxConnectionsPerServer() => (int)InvokeNativeHandlerMethod("get_MaxConnectionsPerServer"); + + [DynamicDependency("set_MaxConnectionsPerServer", NativeHandlerType, AssemblyName)] + private void SetMaxConnectionsPerServer(int value) => InvokeNativeHandlerMethod("set_MaxConnectionsPerServer", value); + + [DynamicDependency("get_MaxResponseHeadersLength", NativeHandlerType, AssemblyName)] + private int GetMaxResponseHeadersLength() => (int)InvokeNativeHandlerMethod("get_MaxResponseHeadersLength"); + + [DynamicDependency("set_MaxResponseHeadersLength", NativeHandlerType, AssemblyName)] + private void SetMaxResponseHeadersLength(int value) => InvokeNativeHandlerMethod("set_MaxResponseHeadersLength", value); + + [DynamicDependency("get_ClientCertificateOptions", NativeHandlerType, AssemblyName)] + private ClientCertificateOption GetClientCertificateOptions() => (ClientCertificateOption)InvokeNativeHandlerMethod("get_ClientCertificateOptions"); + + [DynamicDependency("set_ClientCertificateOptions", NativeHandlerType, AssemblyName)] + private void SetClientCertificateOptions(ClientCertificateOption value) => InvokeNativeHandlerMethod("set_ClientCertificateOptions", value); + + [DynamicDependency("get_ClientCertificates", NativeHandlerType, AssemblyName)] + private X509CertificateCollection GetClientCertificates() => (X509CertificateCollection)InvokeNativeHandlerMethod("get_ClientCertificates"); + + [DynamicDependency("get_CheckCertificateRevocationList", NativeHandlerType, AssemblyName)] + private bool GetCheckCertificateRevocationList() => (bool)InvokeNativeHandlerMethod("get_CheckCertificateRevocationList"); + + [DynamicDependency("set_CheckCertificateRevocationList", NativeHandlerType, AssemblyName)] + private void SetCheckCertificateRevocationList(bool value) => InvokeNativeHandlerMethod("set_CheckCertificateRevocationList", value); + + [DynamicDependency("get_SslProtocols", NativeHandlerType, AssemblyName)] + private SslProtocols GetSslProtocols() => (SslProtocols)InvokeNativeHandlerMethod("get_SslProtocols"); + + [DynamicDependency("set_SslProtocols", NativeHandlerType, AssemblyName)] + private void SetSslProtocols(SslProtocols value) => InvokeNativeHandlerMethod("set_SslProtocols", value); + + [DynamicDependency("get_Properties", NativeHandlerType, AssemblyName)] + private IDictionary GetProperties() => (IDictionary)InvokeNativeHandlerMethod("get_Properties"); + + [DynamicDependency("get_SupportsAutomaticDecompression", NativeHandlerType, AssemblyName)] + private bool GetSupportsAutomaticDecompression() => (bool)InvokeNativeHandlerMethod("get_SupportsAutomaticDecompression"); + + [DynamicDependency("get_SupportsProxy", NativeHandlerType, AssemblyName)] + private bool GetSupportsProxy() => (bool)InvokeNativeHandlerMethod("get_SupportsProxy"); + + [DynamicDependency("get_SupportsRedirectConfiguration", NativeHandlerType, AssemblyName)] + private bool GetSupportsRedirectConfiguration() => (bool)InvokeNativeHandlerMethod("get_SupportsRedirectConfiguration"); + + [DynamicDependency("get_AutomaticDecompression", NativeHandlerType, AssemblyName)] + private DecompressionMethods GetAutomaticDecompression() => (DecompressionMethods)InvokeNativeHandlerMethod("get_AutomaticDecompression"); + + [DynamicDependency("set_AutomaticDecompression", NativeHandlerType, AssemblyName)] + private void SetAutomaticDecompression(DecompressionMethods value) => InvokeNativeHandlerMethod("set_AutomaticDecompression", value); + + [DynamicDependency("get_UseProxy", NativeHandlerType, AssemblyName)] + private bool GetUseProxy() => (bool)InvokeNativeHandlerMethod("get_UseProxy"); + + [DynamicDependency("set_UseProxy", NativeHandlerType, AssemblyName)] + private void SetUseProxy(bool value) => InvokeNativeHandlerMethod("set_UseProxy", value); + + [DynamicDependency("get_Proxy", NativeHandlerType, AssemblyName)] + private IWebProxy GetProxy() => (IWebProxy)InvokeNativeHandlerMethod("get_Proxy"); + + [DynamicDependency("set_Proxy", NativeHandlerType, AssemblyName)] + private void SetProxy(IWebProxy value) => InvokeNativeHandlerMethod("set_Proxy", value); + + [DynamicDependency("get_PreAuthenticate", NativeHandlerType, AssemblyName)] + private bool GetPreAuthenticate() => (bool)InvokeNativeHandlerMethod("get_PreAuthenticate"); + + [DynamicDependency("set_PreAuthenticate", NativeHandlerType, AssemblyName)] + private void SetPreAuthenticate(bool value) => InvokeNativeHandlerMethod("set_PreAuthenticate", value); + + [DynamicDependency("get_MaxAutomaticRedirections", NativeHandlerType, AssemblyName)] + private int GetMaxAutomaticRedirections() => (int)InvokeNativeHandlerMethod("get_MaxAutomaticRedirections"); + + [DynamicDependency("set_MaxAutomaticRedirections", NativeHandlerType, AssemblyName)] + private void SetMaxAutomaticRedirections(int value) => InvokeNativeHandlerMethod("set_MaxAutomaticRedirections", value); + [DynamicDependency("get_UseCookies", NativeHandlerType, AssemblyName)] private bool GetUseCookies() => (bool)InvokeNativeHandlerMethod("get_UseCookies"); diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs index cd94e67..1f11fbf 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs @@ -86,8 +86,6 @@ namespace System.Net.Http } [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public DecompressionMethods AutomaticDecompression { get => _underlyingHandler.AutomaticDecompression; @@ -95,8 +93,6 @@ namespace System.Net.Http } [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public bool UseProxy { get => _underlyingHandler.UseProxy; @@ -112,10 +108,7 @@ namespace System.Net.Http set => _underlyingHandler.Proxy = value; } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public ICredentials? DefaultProxyCredentials { get => _underlyingHandler.DefaultProxyCredentials; @@ -123,8 +116,6 @@ namespace System.Net.Http } [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public bool PreAuthenticate { get => _underlyingHandler.PreAuthenticate; @@ -168,18 +159,13 @@ namespace System.Net.Http } [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public int MaxAutomaticRedirections { get => _underlyingHandler.MaxAutomaticRedirections; set => _underlyingHandler.MaxAutomaticRedirections = value; } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public int MaxConnectionsPerServer { get => _underlyingHandler.MaxConnectionsPerServer; @@ -219,19 +205,13 @@ namespace System.Net.Http } } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public int MaxResponseHeadersLength { get => _underlyingHandler.MaxResponseHeadersLength; set => _underlyingHandler.MaxResponseHeadersLength = value; } - [UnsupportedOSPlatform("android")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public ClientCertificateOption ClientCertificateOptions { get => _clientCertificateOptions; @@ -265,10 +245,7 @@ namespace System.Net.Http } } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public X509CertificateCollection ClientCertificates { get @@ -283,10 +260,7 @@ namespace System.Net.Http } } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public Func? ServerCertificateCustomValidationCallback { #if TARGET_BROWSER @@ -304,10 +278,7 @@ namespace System.Net.Http #endif } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public bool CheckCertificateRevocationList { get => _underlyingHandler.SslOptions.CertificateRevocationCheckMode == X509RevocationMode.Online; @@ -318,10 +289,7 @@ namespace System.Net.Http } } - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public SslProtocols SslProtocols { get => _underlyingHandler.SslOptions.EnabledSslProtocols; @@ -332,9 +300,6 @@ namespace System.Net.Http } } - [UnsupportedOSPlatform("android")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public IDictionary Properties => _underlyingHandler.Properties; // @@ -353,10 +318,7 @@ namespace System.Net.Http // lazy-load the validator func so it can be trimmed by the ILLinker if it isn't used. private static Func? s_dangerousAcceptAnyServerCertificateValidator; - [UnsupportedOSPlatform("android")] [UnsupportedOSPlatform("browser")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public static Func DangerousAcceptAnyServerCertificateValidator => Volatile.Read(ref s_dangerousAcceptAnyServerCertificateValidator) ?? Interlocked.CompareExchange(ref s_dangerousAcceptAnyServerCertificateValidator, delegate { return true; }, null) ?? diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.iOS.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.iOS.cs index ff9e910..915c1c9 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.iOS.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.iOS.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Net.Security; using System.Reflection; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; namespace System.Net.Http { @@ -14,9 +18,90 @@ namespace System.Net.Http private const string NativeHandlerType = "System.Net.Http.NSUrlSessionHandler"; private const string AssemblyName = "Xamarin.iOS"; + [DynamicDependency("get_DefaultProxyCredentials", NativeHandlerType, AssemblyName)] + private ICredentials? GetDefaultProxyCredentials() => (ICredentials?)InvokeNativeHandlerMethod("get_DefaultProxyCredentials"); + + [DynamicDependency("set_DefaultProxyCredentials", NativeHandlerType, AssemblyName)] + private void SetDefaultProxyCredentials(ICredentials? value) => InvokeNativeHandlerMethod("set_DefaultProxyCredentials", value); + + [DynamicDependency("get_MaxConnectionsPerServer", NativeHandlerType, AssemblyName)] + private int GetMaxConnectionsPerServer() => (int)InvokeNativeHandlerMethod("get_MaxConnectionsPerServer"); + + [DynamicDependency("set_MaxConnectionsPerServer", NativeHandlerType, AssemblyName)] + private void SetMaxConnectionsPerServer(int value) => InvokeNativeHandlerMethod("set_MaxConnectionsPerServer", value); + + [DynamicDependency("get_MaxResponseHeadersLength", NativeHandlerType, AssemblyName)] + private int GetMaxResponseHeadersLength() => (int)InvokeNativeHandlerMethod("get_MaxResponseHeadersLength"); + + [DynamicDependency("set_MaxResponseHeadersLength", NativeHandlerType, AssemblyName)] + private void SetMaxResponseHeadersLength(int value) => InvokeNativeHandlerMethod("set_MaxResponseHeadersLength", value); + + [DynamicDependency("get_ClientCertificateOptions", NativeHandlerType, AssemblyName)] + private ClientCertificateOption GetClientCertificateOptions() => (ClientCertificateOption)InvokeNativeHandlerMethod("get_ClientCertificateOptions"); + + [DynamicDependency("set_ClientCertificateOptions", NativeHandlerType, AssemblyName)] + private void SetClientCertificateOptions(ClientCertificateOption value) => InvokeNativeHandlerMethod("set_ClientCertificateOptions", value); + + [DynamicDependency("get_ClientCertificates", NativeHandlerType, AssemblyName)] + private X509CertificateCollection GetClientCertificates() => (X509CertificateCollection)InvokeNativeHandlerMethod("get_ClientCertificates"); + + [DynamicDependency("get_CheckCertificateRevocationList", NativeHandlerType, AssemblyName)] + private bool GetCheckCertificateRevocationList() => (bool)InvokeNativeHandlerMethod("get_CheckCertificateRevocationList"); + + [DynamicDependency("set_CheckCertificateRevocationList", NativeHandlerType, AssemblyName)] + private void SetCheckCertificateRevocationList(bool value) => InvokeNativeHandlerMethod("set_CheckCertificateRevocationList", value); + + [DynamicDependency("get_SslProtocols", NativeHandlerType, AssemblyName)] + private SslProtocols GetSslProtocols() => (SslProtocols)InvokeNativeHandlerMethod("get_SslProtocols"); + + [DynamicDependency("set_SslProtocols", NativeHandlerType, AssemblyName)] + private void SetSslProtocols(SslProtocols value) => InvokeNativeHandlerMethod("set_SslProtocols", value); + + [DynamicDependency("get_Properties", NativeHandlerType, AssemblyName)] + private IDictionary GetProperties() => (IDictionary)InvokeNativeHandlerMethod("get_Properties"); + + [DynamicDependency("get_SupportsAutomaticDecompression", NativeHandlerType, AssemblyName)] + private bool GetSupportsAutomaticDecompression() => (bool)InvokeNativeHandlerMethod("get_SupportsAutomaticDecompression"); + + [DynamicDependency("get_SupportsProxy", NativeHandlerType, AssemblyName)] + private bool GetSupportsProxy() => (bool)InvokeNativeHandlerMethod("get_SupportsProxy"); + + [DynamicDependency("get_AutomaticDecompression", NativeHandlerType, AssemblyName)] + private DecompressionMethods GetAutomaticDecompression() => (DecompressionMethods)InvokeNativeHandlerMethod("get_AutomaticDecompression"); + + [DynamicDependency("set_AutomaticDecompression", NativeHandlerType, AssemblyName)] + private void SetAutomaticDecompression(DecompressionMethods value) => InvokeNativeHandlerMethod("set_AutomaticDecompression", value); + + [DynamicDependency("get_UseProxy", NativeHandlerType, AssemblyName)] + private bool GetUseProxy() => (bool)InvokeNativeHandlerMethod("get_UseProxy"); + + [DynamicDependency("set_UseProxy", NativeHandlerType, AssemblyName)] + private void SetUseProxy(bool value) => InvokeNativeHandlerMethod("set_UseProxy", value); + + [DynamicDependency("get_Proxy", NativeHandlerType, AssemblyName)] + private IWebProxy GetProxy() => (IWebProxy)InvokeNativeHandlerMethod("get_Proxy"); + + [DynamicDependency("set_Proxy", NativeHandlerType, AssemblyName)] + private void SetProxy(IWebProxy value) => InvokeNativeHandlerMethod("set_Proxy", value); + + [DynamicDependency("get_PreAuthenticate", NativeHandlerType, AssemblyName)] + private bool GetPreAuthenticate() => (bool)InvokeNativeHandlerMethod("get_PreAuthenticate"); + + [DynamicDependency("set_PreAuthenticate", NativeHandlerType, AssemblyName)] + private void SetPreAuthenticate(bool value) => InvokeNativeHandlerMethod("set_PreAuthenticate", value); + + [DynamicDependency("get_MaxAutomaticRedirections", NativeHandlerType, AssemblyName)] + private int GetMaxAutomaticRedirections() => (int)InvokeNativeHandlerMethod("get_MaxAutomaticRedirections"); + + [DynamicDependency("set_MaxAutomaticRedirections", NativeHandlerType, AssemblyName)] + private void SetMaxAutomaticRedirections(int value) => InvokeNativeHandlerMethod("set_MaxAutomaticRedirections", value); + [DynamicDependency("get_UseCookies", NativeHandlerType, AssemblyName)] private bool GetUseCookies() => (bool)InvokeNativeHandlerMethod("get_UseCookies"); + [DynamicDependency("get_SupportsRedirectConfiguration", NativeHandlerType, AssemblyName)] + private bool GetSupportsRedirectConfiguration() => (bool)InvokeNativeHandlerMethod("get_SupportsRedirectConfiguration"); + [DynamicDependency("set_UseCookies", NativeHandlerType, AssemblyName)] private void SetUseCookies(bool value) => InvokeNativeHandlerMethod("set_UseCookies", value); diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.tvOS.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.tvOS.cs index 4eaa6a9..8add42b 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.tvOS.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.tvOS.cs @@ -2,8 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Net.Security; using System.Reflection; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; namespace System.Net.Http { @@ -14,6 +18,87 @@ namespace System.Net.Http private const string NativeHandlerType = "System.Net.Http.NSUrlSessionHandler"; private const string AssemblyName = "Xamarin.TVOS"; + [DynamicDependency("get_DefaultProxyCredentials", NativeHandlerType, AssemblyName)] + private ICredentials? GetDefaultProxyCredentials() => (ICredentials?)InvokeNativeHandlerMethod("get_DefaultProxyCredentials"); + + [DynamicDependency("set_DefaultProxyCredentials", NativeHandlerType, AssemblyName)] + private void SetDefaultProxyCredentials(ICredentials? value) => InvokeNativeHandlerMethod("set_DefaultProxyCredentials", value); + + [DynamicDependency("get_MaxConnectionsPerServer", NativeHandlerType, AssemblyName)] + private int GetMaxConnectionsPerServer() => (int)InvokeNativeHandlerMethod("get_MaxConnectionsPerServer"); + + [DynamicDependency("set_MaxConnectionsPerServer", NativeHandlerType, AssemblyName)] + private void SetMaxConnectionsPerServer(int value) => InvokeNativeHandlerMethod("set_MaxConnectionsPerServer", value); + + [DynamicDependency("get_MaxResponseHeadersLength", NativeHandlerType, AssemblyName)] + private int GetMaxResponseHeadersLength() => (int)InvokeNativeHandlerMethod("get_MaxResponseHeadersLength"); + + [DynamicDependency("set_MaxResponseHeadersLength", NativeHandlerType, AssemblyName)] + private void SetMaxResponseHeadersLength(int value) => InvokeNativeHandlerMethod("set_MaxResponseHeadersLength", value); + + [DynamicDependency("get_ClientCertificateOptions", NativeHandlerType, AssemblyName)] + private ClientCertificateOption GetClientCertificateOptions() => (ClientCertificateOption)InvokeNativeHandlerMethod("get_ClientCertificateOptions"); + + [DynamicDependency("set_ClientCertificateOptions", NativeHandlerType, AssemblyName)] + private void SetClientCertificateOptions(ClientCertificateOption value) => InvokeNativeHandlerMethod("set_ClientCertificateOptions", value); + + [DynamicDependency("get_ClientCertificates", NativeHandlerType, AssemblyName)] + private X509CertificateCollection GetClientCertificates() => (X509CertificateCollection)InvokeNativeHandlerMethod("get_ClientCertificates"); + + [DynamicDependency("get_CheckCertificateRevocationList", NativeHandlerType, AssemblyName)] + private bool GetCheckCertificateRevocationList() => (bool)InvokeNativeHandlerMethod("get_CheckCertificateRevocationList"); + + [DynamicDependency("set_CheckCertificateRevocationList", NativeHandlerType, AssemblyName)] + private void SetCheckCertificateRevocationList(bool value) => InvokeNativeHandlerMethod("set_CheckCertificateRevocationList", value); + + [DynamicDependency("get_SslProtocols", NativeHandlerType, AssemblyName)] + private SslProtocols GetSslProtocols() => (SslProtocols)InvokeNativeHandlerMethod("get_SslProtocols"); + + [DynamicDependency("set_SslProtocols", NativeHandlerType, AssemblyName)] + private void SetSslProtocols(SslProtocols value) => InvokeNativeHandlerMethod("set_SslProtocols", value); + + [DynamicDependency("get_Properties", NativeHandlerType, AssemblyName)] + private IDictionary GetProperties() => (IDictionary)InvokeNativeHandlerMethod("get_Properties"); + + [DynamicDependency("get_SupportsAutomaticDecompression", NativeHandlerType, AssemblyName)] + private bool GetSupportsAutomaticDecompression() => (bool)InvokeNativeHandlerMethod("get_SupportsAutomaticDecompression"); + + [DynamicDependency("get_SupportsProxy", NativeHandlerType, AssemblyName)] + private bool GetSupportsProxy() => (bool)InvokeNativeHandlerMethod("get_SupportsProxy"); + + [DynamicDependency("get_SupportsRedirectConfiguration", NativeHandlerType, AssemblyName)] + private bool GetSupportsRedirectConfiguration() => (bool)InvokeNativeHandlerMethod("get_SupportsRedirectConfiguration"); + + [DynamicDependency("get_AutomaticDecompression", NativeHandlerType, AssemblyName)] + private DecompressionMethods GetAutomaticDecompression() => (DecompressionMethods)InvokeNativeHandlerMethod("get_AutomaticDecompression"); + + [DynamicDependency("set_AutomaticDecompression", NativeHandlerType, AssemblyName)] + private void SetAutomaticDecompression(DecompressionMethods value) => InvokeNativeHandlerMethod("set_AutomaticDecompression", value); + + [DynamicDependency("get_UseProxy", NativeHandlerType, AssemblyName)] + private bool GetUseProxy() => (bool)InvokeNativeHandlerMethod("get_UseProxy"); + + [DynamicDependency("set_UseProxy", NativeHandlerType, AssemblyName)] + private void SetUseProxy(bool value) => InvokeNativeHandlerMethod("set_UseProxy", value); + + [DynamicDependency("get_Proxy", NativeHandlerType, AssemblyName)] + private IWebProxy GetProxy() => (IWebProxy)InvokeNativeHandlerMethod("get_Proxy"); + + [DynamicDependency("set_Proxy", NativeHandlerType, AssemblyName)] + private void SetProxy(IWebProxy value) => InvokeNativeHandlerMethod("set_Proxy", value); + + [DynamicDependency("get_PreAuthenticate", NativeHandlerType, AssemblyName)] + private bool GetPreAuthenticate() => (bool)InvokeNativeHandlerMethod("get_PreAuthenticate"); + + [DynamicDependency("set_PreAuthenticate", NativeHandlerType, AssemblyName)] + private void SetPreAuthenticate(bool value) => InvokeNativeHandlerMethod("set_PreAuthenticate", value); + + [DynamicDependency("get_MaxAutomaticRedirections", NativeHandlerType, AssemblyName)] + private int GetMaxAutomaticRedirections() => (int)InvokeNativeHandlerMethod("get_MaxAutomaticRedirections"); + + [DynamicDependency("set_MaxAutomaticRedirections", NativeHandlerType, AssemblyName)] + private void SetMaxAutomaticRedirections(int value) => InvokeNativeHandlerMethod("set_MaxAutomaticRedirections", value); + [DynamicDependency("get_UseCookies", NativeHandlerType, AssemblyName)] private bool GetUseCookies() => (bool)InvokeNativeHandlerMethod("get_UseCookies"); -- 2.7.4