From 1be159f9faaf5520bf229e3b9f817e6ffe8b6151 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sat, 19 May 2012 23:36:32 -0400 Subject: [PATCH] [WebSockets] Handshake encoding + case insensitivity Updated RFC6455 handshaker to check values case insensitively Made sure RFC6455 handshaker matches encoding properly Added mbstring as a requirement for Ratchet Refs #28, #30 --- Version/FrameInterface.php | 6 ------ Version/RFC6455/HandshakeVerifier.php | 14 ++++++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Version/FrameInterface.php b/Version/FrameInterface.php index 57b27ea..61451cc 100644 --- a/Version/FrameInterface.php +++ b/Version/FrameInterface.php @@ -2,12 +2,6 @@ namespace Ratchet\WebSocket\Version; interface FrameInterface { - /** - * Dunno if I'll use this - * Thinking could be used if a control frame? - */ -// function __invoke(); - /** * @return bool */ diff --git a/Version/RFC6455/HandshakeVerifier.php b/Version/RFC6455/HandshakeVerifier.php index 6898e2e..e9172ef 100644 --- a/Version/RFC6455/HandshakeVerifier.php +++ b/Version/RFC6455/HandshakeVerifier.php @@ -32,10 +32,9 @@ class HandshakeVerifier { * Test the HTTP method. MUST be "GET" * @param string * @return bool - * @todo Look into STD if "get" is valid (am I supposed to do case conversion?) */ public function verifyMethod($val) { - return ('GET' === $val); + return ('get' === mb_strtolower($val, 'ASCII')); } /** @@ -50,7 +49,6 @@ class HandshakeVerifier { /** * @param string * @return bool - * @todo Verify the logic here is correct */ public function verifyRequestURI($val) { if ($val[0] != '/') { @@ -80,7 +78,7 @@ class HandshakeVerifier { * @return bool */ public function verifyUpgradeRequest($val) { - return ('websocket' === $val); + return ('websocket' === mb_strtolower($val, 'ASCII')); } /** @@ -89,12 +87,16 @@ class HandshakeVerifier { * @return bool */ public function verifyConnection($val) { - if ('Upgrade' === $val) { + $val = mb_strtolower($val, 'ASCII'); + + if ('upgrade' === $val) { return true; } + // todo change this to mb_eregi_replace $vals = explode(',', str_replace(', ', ',', $val)); - return (false !== array_search('Upgrade', $vals)); + + return (false !== array_search('upgrade', $vals)); } /**