From 93b30f94d7eb6adbeefbd9999e23790b77c32854 Mon Sep 17 00:00:00 2001 From: sta Date: Wed, 7 Aug 2013 18:01:23 +0900 Subject: [PATCH] Modified validating the connection request and response --- websocket-sharp/HandshakeResponse.cs | 3 +-- websocket-sharp/WebSocket.cs | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/websocket-sharp/HandshakeResponse.cs b/websocket-sharp/HandshakeResponse.cs index 2ed06a9a..1f5bd23a 100644 --- a/websocket-sharp/HandshakeResponse.cs +++ b/websocket-sharp/HandshakeResponse.cs @@ -81,8 +81,7 @@ namespace WebSocketSharp return ProtocolVersion >= HttpVersion.Version11 && StatusCode == "101" && Headers.Contains ("Upgrade", "websocket") && - Headers.Contains ("Connection", "Upgrade") && - !Headers ["Sec-WebSocket-Accept"].IsNullOrEmpty (); + Headers.Contains ("Connection", "Upgrade"); } } diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index bcf952fe..f91e1520 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -1260,19 +1260,20 @@ namespace WebSocketSharp // As server private bool validateConnectionRequest (WebSocketContext context) { + string version; return context.IsWebSocketRequest && validateHostHeader (context.Host) && !context.SecWebSocketKey.IsNullOrEmpty () && - context.Headers.Contains ("Sec-WebSocket-Version", _version); + ((version = context.SecWebSocketVersion) != null && version == _version); } // As client private bool validateConnectionResponse (HandshakeResponse response) { + string accept, version; return response.IsWebSocketResponse && - response.Headers.Contains ("Sec-WebSocket-Accept", createResponseKey ()) && - (!response.Headers.Contains ("Sec-WebSocket-Version") || - response.Headers.Contains ("Sec-WebSocket-Version", _version)); + ((accept = response.Headers ["Sec-WebSocket-Accept"]) != null && accept == createResponseKey ()) && + ((version = response.Headers ["Sec-WebSocket-Version"]) == null || version == _version); } // As server