From a520733ba2e66ffdf10a99eceed5b941e50fcd9f Mon Sep 17 00:00:00 2001 From: sta Date: Fri, 12 Feb 2016 15:17:40 +0900 Subject: [PATCH] [Modify] Replace it --- websocket-sharp/WebSocket.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 141ac697..90e42ed5 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -100,6 +100,7 @@ namespace WebSocketSharp private bool _preAuth; private string _protocol; private string[] _protocols; + private bool _protocolsRequested; private NetworkCredential _proxyCredentials; private Uri _proxyUri; private volatile WebSocketState _readyState; @@ -935,7 +936,8 @@ namespace WebSocketSharp headers["Sec-WebSocket-Key"] = _base64Key; - if (_protocols != null) + _protocolsRequested = _protocols != null; + if (_protocolsRequested) headers["Sec-WebSocket-Protocol"] = _protocols.ToString (", "); _extensionsRequested = _compression != CompressionMethod.None; @@ -1006,7 +1008,7 @@ namespace WebSocketSharp if (!checkIfValidHandshakeResponse (res, out msg)) throw new WebSocketException (CloseStatusCode.ProtocolError, msg); - if (_protocols != null) + if (_protocolsRequested) _protocol = res.Headers["Sec-WebSocket-Protocol"]; if (_extensionsRequested) @@ -1746,12 +1748,12 @@ namespace WebSocketSharp private bool validateSecWebSocketProtocolHeader (string value) { if (value == null) - return _protocols == null; + return !_protocolsRequested; if (value.Length == 0) return false; - if (_protocols == null || !_protocols.Contains (p => p == value)) + if (!_protocolsRequested || !_protocols.Contains (p => p == value)) return false; return true;