Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ac33201

Browse files
authored
Fix subprotocol check in WebSocketHandle.Managed (#25645)
1 parent 8f8b04a commit ac33201

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,15 @@ public async Task ConnectAsyncCore(Uri uri, CancellationToken cancellationToken,
177177
{
178178
Debug.Assert(subprotocolEnumerableValues is string[]);
179179
string[] subprotocolArray = (string[])subprotocolEnumerableValues;
180-
if (subprotocolArray.Length != 1 ||
181-
(subprotocol = options.RequestedSubProtocols.Find(requested => string.Equals(requested, subprotocolArray[0], StringComparison.OrdinalIgnoreCase))) == null)
180+
if (subprotocolArray.Length > 0 && !string.IsNullOrEmpty(subprotocolArray[0]))
182181
{
183-
throw new WebSocketException(
184-
WebSocketError.UnsupportedProtocol,
185-
SR.Format(SR.net_WebSockets_AcceptUnsupportedProtocol, string.Join(", ", options.RequestedSubProtocols), subprotocol));
182+
subprotocol = options.RequestedSubProtocols.Find(requested => string.Equals(requested, subprotocolArray[0], StringComparison.OrdinalIgnoreCase));
183+
if (subprotocol == null)
184+
{
185+
throw new WebSocketException(
186+
WebSocketError.UnsupportedProtocol,
187+
SR.Format(SR.net_WebSockets_AcceptUnsupportedProtocol, string.Join(", ", options.RequestedSubProtocols), string.Join(", ", subprotocolArray)));
188+
}
186189
}
187190
}
188191

0 commit comments

Comments
 (0)