Modified validating the connection request and response

This commit is contained in:
sta 2013-08-07 18:01:23 +09:00
parent ab2ef30f02
commit 93b30f94d7
2 changed files with 6 additions and 6 deletions

View File

@ -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");
}
}

View File

@ -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