From 5a548295779dea0b3ee667088549af652c614c7e Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Thu, 10 Sep 2020 18:26:22 +0300 Subject: [PATCH] Mark some System.Net.Http APIs as unsupported on browser --- .../System.Net.Http/Directory.Build.props | 1 + .../System.Net.Http/ref/System.Net.Http.cs | 17 +++++++++++++++++ .../BrowserHttpHandler/SocketsHttpHandler.cs | 2 ++ .../src/System/Net/Http/HttpClientHandler.cs | 17 +++++++++++++++++ .../SocketsHttpHandler/SocketsHttpHandler.cs | 2 ++ 5 files changed, 39 insertions(+) diff --git a/src/libraries/System.Net.Http/Directory.Build.props b/src/libraries/System.Net.Http/Directory.Build.props index 63f02a0f817ef..d68d22c1b917f 100644 --- a/src/libraries/System.Net.Http/Directory.Build.props +++ b/src/libraries/System.Net.Http/Directory.Build.props @@ -2,5 +2,6 @@ Microsoft + true \ No newline at end of file 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 cc6c8995ac954..1175f4b4f564a 100644 --- a/src/libraries/System.Net.Http/ref/System.Net.Http.cs +++ b/src/libraries/System.Net.Http/ref/System.Net.Http.cs @@ -103,28 +103,44 @@ public partial class HttpClientHandler : System.Net.Http.HttpMessageHandler { public HttpClientHandler() { } public bool AllowAutoRedirect { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Net.DecompressionMethods AutomaticDecompression { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool CheckCertificateRevocationList { get { throw null; } set { } } public System.Net.Http.ClientCertificateOption ClientCertificateOptions { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] 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 { } } public static System.Func DangerousAcceptAnyServerCertificateValidator { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Net.ICredentials? DefaultProxyCredentials { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public int MaxAutomaticRedirections { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public int MaxConnectionsPerServer { get { throw null; } set { } } public long MaxRequestContentBufferSize { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public int MaxResponseHeadersLength { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool PreAuthenticate { get { throw null; } set { } } public System.Collections.Generic.IDictionary Properties { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Net.IWebProxy? Proxy { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Func? ServerCertificateCustomValidationCallback { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Security.Authentication.SslProtocols SslProtocols { get { throw null; } set { } } public virtual bool SupportsAutomaticDecompression { get { throw null; } } public virtual bool SupportsProxy { get { throw null; } } public virtual bool SupportsRedirectConfiguration { get { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool UseCookies { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool UseDefaultCredentials { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool UseProxy { get { throw null; } set { } } protected override void Dispose(bool disposing) { } protected internal override System.Net.Http.HttpResponseMessage Send(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { throw null; } @@ -325,6 +341,7 @@ protected override void SerializeToStream(System.IO.Stream stream, System.Net.Tr protected override System.Threading.Tasks.Task SerializeToStreamAsync(System.IO.Stream stream, System.Net.TransportContext? context, System.Threading.CancellationToken cancellationToken) { throw null; } protected internal override bool TryComputeLength(out long length) { throw null; } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public sealed partial class SocketsHttpHandler : System.Net.Http.HttpMessageHandler { public SocketsHttpHandler() { } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs index 1d7ae3a03813c..c80a8cd7164ec 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs @@ -3,12 +3,14 @@ using System.Collections.Generic; using System.Net.Security; +using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; using System.Diagnostics.CodeAnalysis; namespace System.Net.Http { + [UnsupportedOSPlatform("browser")] public sealed class SocketsHttpHandler : HttpMessageHandler { public static bool IsSupported => false; 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 5540ba7f642cd..79102d0d0ae68 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 @@ -4,6 +4,7 @@ using System.Globalization; using System.Net.Security; using System.Collections.Generic; +using System.Runtime.Versioning; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Threading; @@ -52,12 +53,14 @@ protected override void Dispose(bool disposing) public virtual bool SupportsProxy => _underlyingHandler.SupportsProxy; public virtual bool SupportsRedirectConfiguration => _underlyingHandler.SupportsRedirectConfiguration; + [UnsupportedOSPlatform("browser")] public bool UseCookies { get => _underlyingHandler.UseCookies; set => _underlyingHandler.UseCookies = value; } + [UnsupportedOSPlatform("browser")] public CookieContainer CookieContainer { get => _underlyingHandler.CookieContainer; @@ -72,36 +75,42 @@ public CookieContainer CookieContainer } } + [UnsupportedOSPlatform("browser")] public DecompressionMethods AutomaticDecompression { get => _underlyingHandler.AutomaticDecompression; set => _underlyingHandler.AutomaticDecompression = value; } + [UnsupportedOSPlatform("browser")] public bool UseProxy { get => _underlyingHandler.UseProxy; set => _underlyingHandler.UseProxy = value; } + [UnsupportedOSPlatform("browser")] public IWebProxy? Proxy { get => _underlyingHandler.Proxy; set => _underlyingHandler.Proxy = value; } + [UnsupportedOSPlatform("browser")] public ICredentials? DefaultProxyCredentials { get => _underlyingHandler.DefaultProxyCredentials; set => _underlyingHandler.DefaultProxyCredentials = value; } + [UnsupportedOSPlatform("browser")] public bool PreAuthenticate { get => _underlyingHandler.PreAuthenticate; set => _underlyingHandler.PreAuthenticate = value; } + [UnsupportedOSPlatform("browser")] public bool UseDefaultCredentials { // SocketsHttpHandler doesn't have a separate UseDefaultCredentials property. There @@ -124,6 +133,7 @@ public bool UseDefaultCredentials } } + [UnsupportedOSPlatform("browser")] public ICredentials? Credentials { get => _underlyingHandler.Credentials; @@ -136,12 +146,14 @@ public bool AllowAutoRedirect set => _underlyingHandler.AllowAutoRedirect = value; } + [UnsupportedOSPlatform("browser")] public int MaxAutomaticRedirections { get => _underlyingHandler.MaxAutomaticRedirections; set => _underlyingHandler.MaxAutomaticRedirections = value; } + [UnsupportedOSPlatform("browser")] public int MaxConnectionsPerServer { get => _underlyingHandler.MaxConnectionsPerServer; @@ -181,6 +193,7 @@ public long MaxRequestContentBufferSize } } + [UnsupportedOSPlatform("browser")] public int MaxResponseHeadersLength { get => _underlyingHandler.MaxResponseHeadersLength; @@ -220,6 +233,7 @@ public ClientCertificateOption ClientCertificateOptions } } + [UnsupportedOSPlatform("browser")] public X509CertificateCollection ClientCertificates { get @@ -234,6 +248,7 @@ public X509CertificateCollection ClientCertificates } } + [UnsupportedOSPlatform("browser")] public Func? ServerCertificateCustomValidationCallback { #if TARGETS_BROWSER @@ -251,6 +266,7 @@ public X509CertificateCollection ClientCertificates #endif } + [UnsupportedOSPlatform("browser")] public bool CheckCertificateRevocationList { get => _underlyingHandler.SslOptions.CertificateRevocationCheckMode == X509RevocationMode.Online; @@ -261,6 +277,7 @@ public bool CheckCertificateRevocationList } } + [UnsupportedOSPlatform("browser")] public SslProtocols SslProtocols { get => _underlyingHandler.SslOptions.EnabledSslProtocols; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs index 2aa06f23dec11..585411e9f836c 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Net.Security; +using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; using System.Diagnostics.CodeAnalysis; @@ -11,6 +12,7 @@ namespace System.Net.Http { + [UnsupportedOSPlatform("browser")] public sealed class SocketsHttpHandler : HttpMessageHandler { private readonly HttpConnectionSettings _settings = new HttpConnectionSettings();