Skip to content

Commit

Permalink
Mark some System.Net.Http APIs as unsupported on browser (#42074)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximLipnin committed Sep 11, 2020
1 parent abeadc2 commit 1b18efa
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/libraries/System.Net.Http/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IncludePlatformAttributes>true</IncludePlatformAttributes>
</PropertyGroup>
</Project>
17 changes: 17 additions & 0 deletions src/libraries/System.Net.Http/ref/System.Net.Http.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<System.Net.Http.HttpRequestMessage, System.Security.Cryptography.X509Certificates.X509Certificate2?, System.Security.Cryptography.X509Certificates.X509Chain?, System.Net.Security.SslPolicyErrors, bool> 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<string, object?> 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<System.Net.Http.HttpRequestMessage, System.Security.Cryptography.X509Certificates.X509Certificate2?, System.Security.Cryptography.X509Certificates.X509Chain?, System.Net.Security.SslPolicyErrors, bool>? 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; }
Expand Down Expand Up @@ -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() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
using System.Collections.Generic;
using System.IO;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -124,6 +133,7 @@ public bool UseDefaultCredentials
}
}

[UnsupportedOSPlatform("browser")]
public ICredentials? Credentials
{
get => _underlyingHandler.Credentials;
Expand All @@ -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;
Expand Down Expand Up @@ -181,6 +193,7 @@ public long MaxRequestContentBufferSize
}
}

[UnsupportedOSPlatform("browser")]
public int MaxResponseHeadersLength
{
get => _underlyingHandler.MaxResponseHeadersLength;
Expand Down Expand Up @@ -220,6 +233,7 @@ public ClientCertificateOption ClientCertificateOptions
}
}

[UnsupportedOSPlatform("browser")]
public X509CertificateCollection ClientCertificates
{
get
Expand All @@ -234,6 +248,7 @@ public X509CertificateCollection ClientCertificates
}
}

[UnsupportedOSPlatform("browser")]
public Func<HttpRequestMessage, X509Certificate2?, X509Chain?, SslPolicyErrors, bool>? ServerCertificateCustomValidationCallback
{
#if TARGETS_BROWSER
Expand All @@ -251,6 +266,7 @@ public X509CertificateCollection ClientCertificates
#endif
}

[UnsupportedOSPlatform("browser")]
public bool CheckCertificateRevocationList
{
get => _underlyingHandler.SslOptions.CertificateRevocationCheckMode == X509RevocationMode.Online;
Expand All @@ -261,6 +277,7 @@ public bool CheckCertificateRevocationList
}
}

[UnsupportedOSPlatform("browser")]
public SslProtocols SslProtocols
{
get => _underlyingHandler.SslOptions.EnabledSslProtocols;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
using System.Diagnostics;
using System.IO;
using System.Net.Security;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics.CodeAnalysis;
using System.Text;

namespace System.Net.Http
{
[UnsupportedOSPlatform("browser")]
public sealed class SocketsHttpHandler : HttpMessageHandler
{
private readonly HttpConnectionSettings _settings = new HttpConnectionSettings();
Expand Down

0 comments on commit 1b18efa

Please sign in to comment.