[Foundation] Implement the properties inherited from HttpClientHandler in NSUrlSessionHandler. Fixes #13579. (#14484)

Fixes https://github.com/xamarin/xamarin-macios/issues/13579.
This commit is contained in:
Rolf Bjarne Kvinge 2022-04-04 17:25:54 +02:00 коммит произвёл GitHub
Родитель 6e348f0e65
Коммит 0924eb4ef1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 112 добавлений и 50 удалений

Просмотреть файл

@ -531,84 +531,146 @@ namespace Foundation {
#if NET #if NET
// Properties that will be called by the default HttpClientHandler // Properties that will be called by the default HttpClientHandler
// NSUrlSession handler automatically handles decompression, and there doesn't seem to be a way to turn it off.
// The available decompression algorithms depend on the OS version we're running on, and maybe the target OS version as well,
// so just say we're doing them all, and not do anything in the setter (it doesn't seem to be configurable in NSUrlSession anyways).
public DecompressionMethods AutomaticDecompression { public DecompressionMethods AutomaticDecompression {
get => throw new PlatformNotSupportedException (); get => DecompressionMethods.All;
set => throw new PlatformNotSupportedException (); set { }
} }
public bool CheckCertificateRevocationList { // We're ignoring this property, just like Xamarin.Android does:
get => throw new PlatformNotSupportedException (); // https://github.com/xamarin/xamarin-android/blob/09e8cb5c07ea6c39383185a3f90e53186749b802/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs#L158
set => throw new PlatformNotSupportedException (); [UnsupportedOSPlatform ("ios")]
} [UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
public bool CheckCertificateRevocationList { get; set; } = false;
public X509CertificateCollection ClientCertificates { // We're ignoring this property, just like Xamarin.Android does:
get => throw new PlatformNotSupportedException (); // https://github.com/xamarin/xamarin-android/blob/09e8cb5c07ea6c39383185a3f90e53186749b802/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs#L150
} // Note: we can't return null (like Xamarin.Android does), because the return type isn't nullable.
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
public X509CertificateCollection ClientCertificates { get { return new X509CertificateCollection (); } }
public ClientCertificateOption ClientCertificateOptions { // We're ignoring this property, just like Xamarin.Android does:
get => throw new PlatformNotSupportedException (); // https://github.com/xamarin/xamarin-android/blob/09e8cb5c07ea6c39383185a3f90e53186749b802/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs#L148
set => throw new PlatformNotSupportedException (); [UnsupportedOSPlatform ("ios")]
} [UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
public ClientCertificateOption ClientCertificateOptions { get; set; }
public ICredentials DefaultProxyCredentials { // We're ignoring this property, just like Xamarin.Android does:
get => throw new PlatformNotSupportedException (); // https://github.com/xamarin/xamarin-android/blob/09e8cb5c07ea6c39383185a3f90e53186749b802/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs#L152
set => throw new PlatformNotSupportedException (); [UnsupportedOSPlatform ("ios")]
} [UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
public ICredentials? DefaultProxyCredentials { get; set; }
public int MaxAutomaticRedirections { public int MaxAutomaticRedirections {
get => throw new PlatformNotSupportedException (); get => int.MaxValue;
set => throw new PlatformNotSupportedException (); set {
// I believe it's possible to implement support for MaxAutomaticRedirections (it just has to be done)
if (value != int.MaxValue)
throw new ArgumentOutOfRangeException (nameof (value), value, "It's not possible to lower the max number of automatic redirections.");;
}
} }
public int MaxConnectionsPerServer { // We're ignoring this property, just like Xamarin.Android does:
get => throw new PlatformNotSupportedException (); // https://github.com/xamarin/xamarin-android/blob/09e8cb5c07ea6c39383185a3f90e53186749b802/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs#L154
set => throw new PlatformNotSupportedException (); [UnsupportedOSPlatform ("ios")]
} [UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
public int MaxConnectionsPerServer { get; set; } = int.MaxValue;
public int MaxResponseHeadersLength { // We're ignoring this property, just like Xamarin.Android does:
get => throw new PlatformNotSupportedException (); // https://github.com/xamarin/xamarin-android/blob/09e8cb5c07ea6c39383185a3f90e53186749b802/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs#L156
set => throw new PlatformNotSupportedException (); [UnsupportedOSPlatform ("ios")]
} [UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
public int MaxResponseHeadersLength { get; set; } = 64; // Units in K (1024) bytes.
// We don't support PreAuthenticate, so always return false, and ignore any attempts to change it.
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
public bool PreAuthenticate { public bool PreAuthenticate {
get => throw new PlatformNotSupportedException (); get => false;
set { }
}
// We're ignoring this property, just like Xamarin.Android does:
// https://github.com/xamarin/xamarin-android/blob/09e8cb5c07ea6c39383185a3f90e53186749b802/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs#L167
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
public IDictionary<string, object>? Properties { get { return null; } }
// We dont support any custom proxies, and don't let anybody wonder why their proxy isn't
// being used if they try to assign one (in any case we also return false from 'SupportsProxy').
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
public IWebProxy? Proxy {
get => null;
set => throw new PlatformNotSupportedException (); set => throw new PlatformNotSupportedException ();
} }
public IDictionary<string, object> Properties { // There doesn't seem to be a trivial way to specify the protocols to accept (or not)
get => throw new PlatformNotSupportedException (); // It might be possible to reject some protocols in code during the challenge phase,
} // but accepting earlier (unsafe) protocols requires adding entires to the Info.plist,
// which means it's not trivial to detect/accept/reject from code here.
// Currently the default for Apple platforms is to accept TLS v1.2 and v1.3, so default
// to that value, and ignore any changes to it.
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("macos")]
public SslProtocols SslProtocols { get; set; } = SslProtocols.Tls12 | SslProtocols.Tls13;
public IWebProxy Proxy { // We're ignoring this property, just like Xamarin.Android does:
get => throw new PlatformNotSupportedException (); // https://github.com/xamarin/xamarin-android/blob/09e8cb5c07ea6c39383185a3f90e53186749b802/src/Mono.Android/Xamarin.Android.Net/AndroidMessageHandler.cs#L160
set => throw new PlatformNotSupportedException (); [UnsupportedOSPlatform ("ios")]
} [UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("tvos")]
public SslProtocols SslProtocols { [UnsupportedOSPlatform ("macos")]
get => throw new PlatformNotSupportedException (); public Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool>? ServerCertificateCustomValidationCallback { get; set; }
set => throw new PlatformNotSupportedException ();
}
public Func<HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, bool> ServerCertificateCustomValidationCallback {
get => throw new PlatformNotSupportedException ();
set => throw new PlatformNotSupportedException ();
}
// There's no way to turn off automatic decompression, so yes, we support it
public bool SupportsAutomaticDecompression { public bool SupportsAutomaticDecompression {
get => throw new PlatformNotSupportedException (); get => true;
} }
// We don't support using custom proxies, but NSUrlSession will automatically use any proxies configured in the OS.
public bool SupportsProxy { public bool SupportsProxy {
get => throw new PlatformNotSupportedException (); get => false;
} }
// We support the AllowAutoRedirect property, but we don't support changing the MaxAutomaticRedirections value,
// so be safe here and say we don't support redirect configuration.
public bool SupportsRedirectConfiguration { public bool SupportsRedirectConfiguration {
get => throw new PlatformNotSupportedException (); get => false;
} }
// NSUrlSession will automatically use any proxies configured in the OS (so always return true in the getter).
// There doesn't seem to be a way to turn this off, so throw if someone attempts to disable this.
public bool UseProxy { public bool UseProxy {
get => throw new PlatformNotSupportedException (); get => true;
set => throw new PlatformNotSupportedException (); set {
if (!value)
throw new ArgumentOutOfRangeException (nameof (value), value, "It's not possible to disable the use of system proxies.");;
}
} }
#endif // NET #endif // NET