Skip to content

Commit 1b18efa

Browse files
authored
Mark some System.Net.Http APIs as unsupported on browser (#42074)
1 parent abeadc2 commit 1b18efa

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

src/libraries/System.Net.Http/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<Import Project="..\Directory.Build.props" />
33
<PropertyGroup>
44
<StrongNameKeyId>Microsoft</StrongNameKeyId>
5+
<IncludePlatformAttributes>true</IncludePlatformAttributes>
56
</PropertyGroup>
67
</Project>

src/libraries/System.Net.Http/ref/System.Net.Http.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,44 @@ public partial class HttpClientHandler : System.Net.Http.HttpMessageHandler
103103
{
104104
public HttpClientHandler() { }
105105
public bool AllowAutoRedirect { get { throw null; } set { } }
106+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
106107
public System.Net.DecompressionMethods AutomaticDecompression { get { throw null; } set { } }
108+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
107109
public bool CheckCertificateRevocationList { get { throw null; } set { } }
108110
public System.Net.Http.ClientCertificateOption ClientCertificateOptions { get { throw null; } set { } }
111+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
109112
public System.Security.Cryptography.X509Certificates.X509CertificateCollection ClientCertificates { get { throw null; } }
113+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
110114
public System.Net.CookieContainer CookieContainer { get { throw null; } set { } }
115+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
111116
public System.Net.ICredentials? Credentials { get { throw null; } set { } }
112117
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; } }
118+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
113119
public System.Net.ICredentials? DefaultProxyCredentials { get { throw null; } set { } }
120+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
114121
public int MaxAutomaticRedirections { get { throw null; } set { } }
122+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
115123
public int MaxConnectionsPerServer { get { throw null; } set { } }
116124
public long MaxRequestContentBufferSize { get { throw null; } set { } }
125+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
117126
public int MaxResponseHeadersLength { get { throw null; } set { } }
127+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
118128
public bool PreAuthenticate { get { throw null; } set { } }
119129
public System.Collections.Generic.IDictionary<string, object?> Properties { get { throw null; } }
130+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
120131
public System.Net.IWebProxy? Proxy { get { throw null; } set { } }
132+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
121133
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 { } }
134+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
122135
public System.Security.Authentication.SslProtocols SslProtocols { get { throw null; } set { } }
123136
public virtual bool SupportsAutomaticDecompression { get { throw null; } }
124137
public virtual bool SupportsProxy { get { throw null; } }
125138
public virtual bool SupportsRedirectConfiguration { get { throw null; } }
139+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
126140
public bool UseCookies { get { throw null; } set { } }
141+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
127142
public bool UseDefaultCredentials { get { throw null; } set { } }
143+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
128144
public bool UseProxy { get { throw null; } set { } }
129145
protected override void Dispose(bool disposing) { }
130146
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
325341
protected override System.Threading.Tasks.Task SerializeToStreamAsync(System.IO.Stream stream, System.Net.TransportContext? context, System.Threading.CancellationToken cancellationToken) { throw null; }
326342
protected internal override bool TryComputeLength(out long length) { throw null; }
327343
}
344+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
328345
public sealed partial class SocketsHttpHandler : System.Net.Http.HttpMessageHandler
329346
{
330347
public SocketsHttpHandler() { }

src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/SocketsHttpHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Net.Security;
7+
using System.Runtime.Versioning;
78
using System.Threading;
89
using System.Threading.Tasks;
910
using System.Diagnostics.CodeAnalysis;
1011

1112
namespace System.Net.Http
1213
{
14+
[UnsupportedOSPlatform("browser")]
1315
public sealed class SocketsHttpHandler : HttpMessageHandler
1416
{
1517
public static bool IsSupported => false;

src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Globalization;
55
using System.Net.Security;
66
using System.Collections.Generic;
7+
using System.Runtime.Versioning;
78
using System.Security.Authentication;
89
using System.Security.Cryptography.X509Certificates;
910
using System.Threading;
@@ -52,12 +53,14 @@ protected override void Dispose(bool disposing)
5253
public virtual bool SupportsProxy => _underlyingHandler.SupportsProxy;
5354
public virtual bool SupportsRedirectConfiguration => _underlyingHandler.SupportsRedirectConfiguration;
5455

56+
[UnsupportedOSPlatform("browser")]
5557
public bool UseCookies
5658
{
5759
get => _underlyingHandler.UseCookies;
5860
set => _underlyingHandler.UseCookies = value;
5961
}
6062

63+
[UnsupportedOSPlatform("browser")]
6164
public CookieContainer CookieContainer
6265
{
6366
get => _underlyingHandler.CookieContainer;
@@ -72,36 +75,42 @@ public CookieContainer CookieContainer
7275
}
7376
}
7477

78+
[UnsupportedOSPlatform("browser")]
7579
public DecompressionMethods AutomaticDecompression
7680
{
7781
get => _underlyingHandler.AutomaticDecompression;
7882
set => _underlyingHandler.AutomaticDecompression = value;
7983
}
8084

85+
[UnsupportedOSPlatform("browser")]
8186
public bool UseProxy
8287
{
8388
get => _underlyingHandler.UseProxy;
8489
set => _underlyingHandler.UseProxy = value;
8590
}
8691

92+
[UnsupportedOSPlatform("browser")]
8793
public IWebProxy? Proxy
8894
{
8995
get => _underlyingHandler.Proxy;
9096
set => _underlyingHandler.Proxy = value;
9197
}
9298

99+
[UnsupportedOSPlatform("browser")]
93100
public ICredentials? DefaultProxyCredentials
94101
{
95102
get => _underlyingHandler.DefaultProxyCredentials;
96103
set => _underlyingHandler.DefaultProxyCredentials = value;
97104
}
98105

106+
[UnsupportedOSPlatform("browser")]
99107
public bool PreAuthenticate
100108
{
101109
get => _underlyingHandler.PreAuthenticate;
102110
set => _underlyingHandler.PreAuthenticate = value;
103111
}
104112

113+
[UnsupportedOSPlatform("browser")]
105114
public bool UseDefaultCredentials
106115
{
107116
// SocketsHttpHandler doesn't have a separate UseDefaultCredentials property. There
@@ -124,6 +133,7 @@ public bool UseDefaultCredentials
124133
}
125134
}
126135

136+
[UnsupportedOSPlatform("browser")]
127137
public ICredentials? Credentials
128138
{
129139
get => _underlyingHandler.Credentials;
@@ -136,12 +146,14 @@ public bool AllowAutoRedirect
136146
set => _underlyingHandler.AllowAutoRedirect = value;
137147
}
138148

149+
[UnsupportedOSPlatform("browser")]
139150
public int MaxAutomaticRedirections
140151
{
141152
get => _underlyingHandler.MaxAutomaticRedirections;
142153
set => _underlyingHandler.MaxAutomaticRedirections = value;
143154
}
144155

156+
[UnsupportedOSPlatform("browser")]
145157
public int MaxConnectionsPerServer
146158
{
147159
get => _underlyingHandler.MaxConnectionsPerServer;
@@ -181,6 +193,7 @@ public long MaxRequestContentBufferSize
181193
}
182194
}
183195

196+
[UnsupportedOSPlatform("browser")]
184197
public int MaxResponseHeadersLength
185198
{
186199
get => _underlyingHandler.MaxResponseHeadersLength;
@@ -220,6 +233,7 @@ public ClientCertificateOption ClientCertificateOptions
220233
}
221234
}
222235

236+
[UnsupportedOSPlatform("browser")]
223237
public X509CertificateCollection ClientCertificates
224238
{
225239
get
@@ -234,6 +248,7 @@ public X509CertificateCollection ClientCertificates
234248
}
235249
}
236250

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

269+
[UnsupportedOSPlatform("browser")]
254270
public bool CheckCertificateRevocationList
255271
{
256272
get => _underlyingHandler.SslOptions.CertificateRevocationCheckMode == X509RevocationMode.Online;
@@ -261,6 +277,7 @@ public bool CheckCertificateRevocationList
261277
}
262278
}
263279

280+
[UnsupportedOSPlatform("browser")]
264281
public SslProtocols SslProtocols
265282
{
266283
get => _underlyingHandler.SslOptions.EnabledSslProtocols;

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
using System.Diagnostics;
66
using System.IO;
77
using System.Net.Security;
8+
using System.Runtime.Versioning;
89
using System.Threading;
910
using System.Threading.Tasks;
1011
using System.Diagnostics.CodeAnalysis;
1112
using System.Text;
1213

1314
namespace System.Net.Http
1415
{
16+
[UnsupportedOSPlatform("browser")]
1517
public sealed class SocketsHttpHandler : HttpMessageHandler
1618
{
1719
private readonly HttpConnectionSettings _settings = new HttpConnectionSettings();

0 commit comments

Comments
 (0)