From 2996c08728fa54a798f53e2dad84682a9c6c407c Mon Sep 17 00:00:00 2001 From: Mike Almond Date: Wed, 1 Feb 2012 13:16:59 -0500 Subject: [PATCH] [REFACTOR] Fixing some code based on unit tests Change the response to send the proper header and fix the generate key method to fail properly when no spaces are present --- lib/Ratchet/Application/WebSocket/Version/Hixie76.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Ratchet/Application/WebSocket/Version/Hixie76.php b/lib/Ratchet/Application/WebSocket/Version/Hixie76.php index ce5ad73..ad70daa 100644 --- a/lib/Ratchet/Application/WebSocket/Version/Hixie76.php +++ b/lib/Ratchet/Application/WebSocket/Version/Hixie76.php @@ -38,10 +38,8 @@ class Hixie76 implements VersionInterface { $headers['Sec-WebSocket-Protocol'] = $request->getHeader('Sec-WebSocket-Protocol'); } - $response = new \Guzzle\Http\Message\Response(101, $headers, $body); + $response = new \Guzzle\Http\Message\Response('HTTP/1.1 101 WebSocket Protocol Handshake', $headers, $body); return $response; - - } public function newMessage() { @@ -56,10 +54,13 @@ class Hixie76 implements VersionInterface { return chr(0) . $message . chr(255); } - protected function generateKeyNumber($key) { + public function generateKeyNumber($key) { + if (substr_count($key, ' ') == 0) { + return ''; + } $int = preg_replace('[\D]', '', $key) / substr_count($key, ' '); - return (is_int($int) && substr_count($key, ' ') > 0) ? $int : ''; + return (is_int($int)) ? $int : ''; }