Skip to content

Commit

Permalink
Mark System.Net.WebSockets.ClientWebSocketOptions APIs as unsupported…
Browse files Browse the repository at this point in the history
… on Browser (dotnet#41963)

* Mark System.Net.WebSockets.ClientWebSocketOptions APIs as unsupported on Browser

* Add the attributes to non-browser version of ClientWebSocketOptions class to avoid build error

* Add using

* Include platform attributes
  • Loading branch information
MaximLipnin authored and Mitchell Hwang committed Sep 8, 2020
1 parent 4a888d3 commit 0705527
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
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>
Original file line number Diff line number Diff line change
Expand Up @@ -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<byte> buffer) { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public void SetRequestHeader(string headerName, string? headerValue) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.Versioning;
using System.Security.Cryptography.X509Certificates;

namespace System.Net.WebSockets
Expand All @@ -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();
Expand Down Expand Up @@ -85,17 +93,20 @@ public void AddSubProtocol(string subProtocol)

internal List<string> RequestedSubProtocols => _requestedSubProtocols ??= new List<string>();

[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<byte> buffer)
{
throw new PlatformNotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,6 +30,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)
{
Expand All @@ -42,6 +44,7 @@ public void SetRequestHeader(string headerName, string? headerValue)

internal List<string> RequestedSubProtocols => _requestedSubProtocols ??= new List<string>();

[UnsupportedOSPlatform("browser")]
public bool UseDefaultCredentials
{
get => _useDefaultCredentials;
Expand All @@ -52,6 +55,7 @@ public bool UseDefaultCredentials
}
}

[UnsupportedOSPlatform("browser")]
public ICredentials? Credentials
{
get => _credentials;
Expand All @@ -62,6 +66,7 @@ public ICredentials? Credentials
}
}

[UnsupportedOSPlatform("browser")]
public IWebProxy? Proxy
{
get => _proxy;
Expand All @@ -72,6 +77,7 @@ public IWebProxy? Proxy
}
}

[UnsupportedOSPlatform("browser")]
public X509CertificateCollection ClientCertificates
{
get => _clientCertificates ??= new X509CertificateCollection();
Expand All @@ -82,6 +88,7 @@ public X509CertificateCollection ClientCertificates
}
}

[UnsupportedOSPlatform("browser")]
public RemoteCertificateValidationCallback? RemoteCertificateValidationCallback
{
get => _remoteCertificateValidationCallback;
Expand All @@ -92,6 +99,7 @@ public RemoteCertificateValidationCallback? RemoteCertificateValidationCallback
}
}

[UnsupportedOSPlatform("browser")]
public CookieContainer? Cookies
{
get => _cookies;
Expand Down Expand Up @@ -123,6 +131,7 @@ public void AddSubProtocol(string subProtocol)
subprotocols.Add(subProtocol);
}

[UnsupportedOSPlatform("browser")]
public TimeSpan KeepAliveInterval
{
get => _keepAliveInterval;
Expand All @@ -142,6 +151,7 @@ public TimeSpan KeepAliveInterval
internal int ReceiveBufferSize => _receiveBufferSize;
internal ArraySegment<byte>? Buffer => _buffer;

[UnsupportedOSPlatform("browser")]
public void SetBuffer(int receiveBufferSize, int sendBufferSize)
{
ThrowIfReadOnly();
Expand All @@ -159,6 +169,7 @@ public void SetBuffer(int receiveBufferSize, int sendBufferSize)
_buffer = null;
}

[UnsupportedOSPlatform("browser")]
public void SetBuffer(int receiveBufferSize, int sendBufferSize, ArraySegment<byte> buffer)
{
ThrowIfReadOnly();
Expand Down

0 comments on commit 0705527

Please sign in to comment.