From 502115435d88a44cd2a30db8e0b49d800edc978f Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Wed, 9 Oct 2019 19:47:17 +0200 Subject: [PATCH] [System.Net.Http] Make HttpClientHandler on WatchOS always fallback to platform handler. This simplifies HttpClientHandler in shared libraries and the "default" socket handler would always throw PNSE anyway --- .../System.Net.Http/HttpClient.macios.cs | 3 +- .../System.Net.Http/HttpClientHandler.xi.cs | 148 +++++++++++++++++++++ ...touch_watch_System.Net.Http.dll.exclude.sources | 7 - .../monotouch_watch_System.Net.Http.dll.sources | 37 +++++- 4 files changed, 184 insertions(+), 11 deletions(-) create mode 100644 mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.xi.cs delete mode 100644 mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.exclude.sources rewrite mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.sources (68%) diff --git a/mcs/class/System.Net.Http/System.Net.Http/HttpClient.macios.cs b/mcs/class/System.Net.Http/System.Net.Http/HttpClient.macios.cs index a60a7941b23..fb0ca1dfbc9 100644 --- a/mcs/class/System.Net.Http/System.Net.Http/HttpClient.macios.cs +++ b/mcs/class/System.Net.Http/System.Net.Http/HttpClient.macios.cs @@ -3,11 +3,12 @@ using System.Reflection; namespace System.Net.Http { public partial class HttpClient { - +#if !MONOTOUCH_WATCH public HttpClient () : this (CreateDefaultHandler ()) { } +#endif static HttpMessageHandler CreateDefaultHandler () { diff --git a/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.xi.cs b/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.xi.cs new file mode 100644 index 00000000000..223762534a7 --- /dev/null +++ b/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.xi.cs @@ -0,0 +1,148 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Net.Security; +using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; +using System.Threading; +using System.Threading.Tasks; + +namespace System.Net.Http +{ + public class HttpClientHandler : HttpMessageHandler + { + HttpMessageHandler platformHandler; + + public HttpClientHandler () + { + // Ensure GetHttpMessageHandler does not recursively call new HttpClientHandler () + platformHandler = ObjCRuntime.RuntimeOptions.GetHttpMessageHandler (); + } + + protected override void Dispose (bool disposing) + { + if (disposing) { + if (platformHandler != null) { + platformHandler.Dispose (); + platformHandler = null; + } + } + base.Dispose (disposing); + } + + public virtual bool SupportsAutomaticDecompression => false; + + public virtual bool SupportsProxy => false; + + public virtual bool SupportsRedirectConfiguration => false; + + public bool UseCookies { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public CookieContainer CookieContainer { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public ClientCertificateOption ClientCertificateOptions { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public X509CertificateCollection ClientCertificates { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public Func ServerCertificateCustomValidationCallback { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public bool CheckCertificateRevocationList { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public SslProtocols SslProtocols { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public DecompressionMethods AutomaticDecompression { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public bool UseProxy { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public IWebProxy Proxy { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public ICredentials DefaultProxyCredentials { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public bool PreAuthenticate { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public bool UseDefaultCredentials { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public ICredentials Credentials { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public bool AllowAutoRedirect { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public int MaxAutomaticRedirections { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public int MaxConnectionsPerServer { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public int MaxResponseHeadersLength { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public long MaxRequestContentBufferSize { + get => throw new PlatformNotSupportedException (); + set => throw new PlatformNotSupportedException (); + } + + public IDictionary Properties => throw new PlatformNotSupportedException (); + + public static Func DangerousAcceptAnyServerCertificateValidator { get; } = delegate { return true; }; + + protected internal override Task SendAsync (HttpRequestMessage request, CancellationToken cancellationToken) + { + if (platformHandler == null) + throw new ObjectDisposedException (GetType().ToString()); + + return platformHandler.SendAsync (request, cancellationToken); + } + } +} \ No newline at end of file diff --git a/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.exclude.sources b/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.exclude.sources deleted file mode 100644 index 5fb1f1caa78..00000000000 --- a/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.exclude.sources +++ /dev/null @@ -1,7 +0,0 @@ -HttpClientHandler.cs -HttpClientHandler.Legacy.cs -IMonoHttpClientHandler.cs -MonoWebRequestHandler.cs - -../../../external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/CancellationHelper.cs -../../../external/corefx/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs diff --git a/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.sources b/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.sources dissimilarity index 68% index 8f6e9ebbc19..6685621bd00 100644 --- a/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.sources +++ b/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.sources @@ -1,3 +1,34 @@ -#include legacy.sources -System.Net.Http/HttpClientHandler.platformnotsupported.cs -System.Net.Http/HttpClient.macios.cs +Assembly/AssemblyInfo.cs + +corefx/NetEventSource.Http.cs + +System.Net.Http/HttpClientHandler.xi.cs +System.Net.Http/HttpClient.macios.cs +HttpRequestMessage.Mono.cs + +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/Headers/*.cs + +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/ByteArrayContent.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/ByteArrayHelpers.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/ClientCertificateOption.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/DelegatingHandler.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/FormUrlEncodedContent.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpClient.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpCompletionOption.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpContent.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpMessageHandler.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpMessageInvoker.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpMethod.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpParseResult.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpRequestException.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpRequestMessage.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpResponseMessage.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpRuleParser.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/HttpUtilities.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/MessageProcessingHandler.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/MultipartContent.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/MultipartFormDataContent.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/ReadOnlyMemoryContent.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/StreamContent.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/StreamToStreamCopy.cs +../../../external/corefx/src/System.Net.Http/src/System/Net/Http/StringContent.cs -- 2.11.4.GIT