From 2492d9b9b31b1299bcf63d218044a2968a5f4725 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Tue, 8 Sep 2020 15:00:11 +0300 Subject: [PATCH 1/4] Mark System.Net.WebSockets.ClientWebSocketOptions APIs as unsupported on Browser --- .../ref/System.Net.WebSockets.Client.cs | 10 ++++++++++ .../BrowserWebSockets/ClientWebSocketOptions.cs | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/libraries/System.Net.WebSockets.Client/ref/System.Net.WebSockets.Client.cs b/src/libraries/System.Net.WebSockets.Client/ref/System.Net.WebSockets.Client.cs index 2d7ea3172807b..cee3a5170b862 100644 --- a/src/libraries/System.Net.WebSockets.Client/ref/System.Net.WebSockets.Client.cs +++ b/src/libraries/System.Net.WebSockets.Client/ref/System.Net.WebSockets.Client.cs @@ -27,16 +27,26 @@ public override void Dispose() { } public sealed partial class ClientWebSocketOptions { internal ClientWebSocketOptions() { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Security.Cryptography.X509Certificates.X509CertificateCollection ClientCertificates { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Net.CookieContainer? Cookies { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Net.ICredentials? Credentials { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.TimeSpan KeepAliveInterval { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Net.IWebProxy? Proxy { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public System.Net.Security.RemoteCertificateValidationCallback? RemoteCertificateValidationCallback { get { throw null; } set { } } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public bool UseDefaultCredentials { get { throw null; } set { } } public void AddSubProtocol(string subProtocol) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void SetBuffer(int receiveBufferSize, int sendBufferSize) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void SetBuffer(int receiveBufferSize, int sendBufferSize, System.ArraySegment buffer) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void SetRequestHeader(string headerName, string? headerValue) { } } } diff --git a/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/ClientWebSocketOptions.cs b/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/ClientWebSocketOptions.cs index e61fced8ca1dc..85b0f025b4650 100644 --- a/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/ClientWebSocketOptions.cs +++ b/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/BrowserWebSockets/ClientWebSocketOptions.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Runtime.Versioning; using System.Security.Cryptography.X509Certificates; namespace System.Net.WebSockets @@ -17,42 +18,49 @@ internal ClientWebSocketOptions() #region HTTP Settings + [UnsupportedOSPlatform("browser")] // Note that some headers are restricted like Host. public void SetRequestHeader(string headerName, string headerValue) { throw new PlatformNotSupportedException(); } + [UnsupportedOSPlatform("browser")] public bool UseDefaultCredentials { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } + [UnsupportedOSPlatform("browser")] public System.Net.ICredentials Credentials { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } + [UnsupportedOSPlatform("browser")] public System.Net.IWebProxy Proxy { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } + [UnsupportedOSPlatform("browser")] public X509CertificateCollection ClientCertificates { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } + [UnsupportedOSPlatform("browser")] public System.Net.Security.RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } + [UnsupportedOSPlatform("browser")] public System.Net.CookieContainer Cookies { get => throw new PlatformNotSupportedException(); @@ -85,17 +93,20 @@ public void AddSubProtocol(string subProtocol) internal List RequestedSubProtocols => _requestedSubProtocols ??= new List(); + [UnsupportedOSPlatform("browser")] public TimeSpan KeepAliveInterval { get => throw new PlatformNotSupportedException(); set => throw new PlatformNotSupportedException(); } + [UnsupportedOSPlatform("browser")] public void SetBuffer(int receiveBufferSize, int sendBufferSize) { throw new PlatformNotSupportedException(); } + [UnsupportedOSPlatform("browser")] public void SetBuffer(int receiveBufferSize, int sendBufferSize, ArraySegment buffer) { throw new PlatformNotSupportedException(); From ba05e66c038138724ab4de48d8e142902d396b91 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Tue, 8 Sep 2020 16:01:40 +0300 Subject: [PATCH 2/4] Add the attributes to non-browser version of ClientWebSocketOptions class to avoid build error --- .../System/Net/WebSockets/ClientWebSocketOptions.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs b/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs index 4c17af9342433..294648bcee491 100644 --- a/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs +++ b/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs @@ -29,6 +29,7 @@ internal ClientWebSocketOptions() { } // prevent external instantiation #region HTTP Settings + [UnsupportedOSPlatform("browser")] // Note that some headers are restricted like Host. public void SetRequestHeader(string headerName, string? headerValue) { @@ -42,6 +43,7 @@ public void SetRequestHeader(string headerName, string? headerValue) internal List RequestedSubProtocols => _requestedSubProtocols ??= new List(); + [UnsupportedOSPlatform("browser")] public bool UseDefaultCredentials { get => _useDefaultCredentials; @@ -52,6 +54,7 @@ public bool UseDefaultCredentials } } + [UnsupportedOSPlatform("browser")] public ICredentials? Credentials { get => _credentials; @@ -62,6 +65,7 @@ public ICredentials? Credentials } } + [UnsupportedOSPlatform("browser")] public IWebProxy? Proxy { get => _proxy; @@ -72,6 +76,7 @@ public IWebProxy? Proxy } } + [UnsupportedOSPlatform("browser")] public X509CertificateCollection ClientCertificates { get => _clientCertificates ??= new X509CertificateCollection(); @@ -82,6 +87,7 @@ public X509CertificateCollection ClientCertificates } } + [UnsupportedOSPlatform("browser")] public RemoteCertificateValidationCallback? RemoteCertificateValidationCallback { get => _remoteCertificateValidationCallback; @@ -92,6 +98,7 @@ public RemoteCertificateValidationCallback? RemoteCertificateValidationCallback } } + [UnsupportedOSPlatform("browser")] public CookieContainer? Cookies { get => _cookies; @@ -123,6 +130,7 @@ public void AddSubProtocol(string subProtocol) subprotocols.Add(subProtocol); } + [UnsupportedOSPlatform("browser")] public TimeSpan KeepAliveInterval { get => _keepAliveInterval; @@ -142,6 +150,7 @@ public TimeSpan KeepAliveInterval internal int ReceiveBufferSize => _receiveBufferSize; internal ArraySegment? Buffer => _buffer; + [UnsupportedOSPlatform("browser")] public void SetBuffer(int receiveBufferSize, int sendBufferSize) { ThrowIfReadOnly(); @@ -159,6 +168,7 @@ public void SetBuffer(int receiveBufferSize, int sendBufferSize) _buffer = null; } + [UnsupportedOSPlatform("browser")] public void SetBuffer(int receiveBufferSize, int sendBufferSize, ArraySegment buffer) { ThrowIfReadOnly(); From ebd619a608abce663f7bde6fb3e028807f3074b7 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Tue, 8 Sep 2020 16:19:43 +0300 Subject: [PATCH 3/4] Add using --- .../src/System/Net/WebSockets/ClientWebSocketOptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs b/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs index 294648bcee491..a7609a0ff0905 100644 --- a/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs +++ b/src/libraries/System.Net.WebSockets.Client/src/System/Net/WebSockets/ClientWebSocketOptions.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Net.Security; +using System.Runtime.Versioning; using System.Security.Cryptography.X509Certificates; using System.Threading; From f8de2feb1ce53c0aad222d0b12149c4edaaf5855 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Tue, 8 Sep 2020 17:19:08 +0300 Subject: [PATCH 4/4] Include platform attributes --- src/libraries/System.Net.WebSockets.Client/Directory.Build.props | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libraries/System.Net.WebSockets.Client/Directory.Build.props b/src/libraries/System.Net.WebSockets.Client/Directory.Build.props index 63f02a0f817ef..d68d22c1b917f 100644 --- a/src/libraries/System.Net.WebSockets.Client/Directory.Build.props +++ b/src/libraries/System.Net.WebSockets.Client/Directory.Build.props @@ -2,5 +2,6 @@ Microsoft + true \ No newline at end of file