From 5676161277bae08e11103a188c43395e8ba8f758 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Sat, 20 Jul 2013 12:38:23 -0400 Subject: [PATCH] [WebSocket] Only select one sub-protocol, fixes #103 --- src/Ratchet/WebSocket/WsServer.php | 16 ++++++---------- tests/unit/WebSocket/WsServerTest.php | 3 ++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Ratchet/WebSocket/WsServer.php b/src/Ratchet/WebSocket/WsServer.php index 460e328..9337934 100644 --- a/src/Ratchet/WebSocket/WsServer.php +++ b/src/Ratchet/WebSocket/WsServer.php @@ -199,19 +199,15 @@ class WsServer implements HttpServerInterface { * @return string */ protected function getSubProtocolString(\Traversable $requested = null) { - if (null === $requested) { - return ''; - } - - $result = array(); - - foreach ($requested as $sub) { - if ($this->isSubProtocolSupported($sub)) { - $result[] = $sub; + if (null !== $requested) { + foreach ($requested as $sub) { + if ($this->isSubProtocolSupported($sub)) { + return $sub; + } } } - return implode(',', $result); + return ''; } /** diff --git a/tests/unit/WebSocket/WsServerTest.php b/tests/unit/WebSocket/WsServerTest.php index 1a3626c..c923e16 100644 --- a/tests/unit/WebSocket/WsServerTest.php +++ b/tests/unit/WebSocket/WsServerTest.php @@ -27,10 +27,11 @@ class WsServerTest extends \PHPUnit_Framework_TestCase { public function protocolProvider() { return array( - array('hello,world', array('hello', 'world'), array('hello', 'world')) + array('hello', array('hello', 'world'), array('hello', 'world')) , array('', array('hello', 'world'), array('wamp')) , array('', array(), null) , array('wamp', array('hello', 'wamp', 'world'), array('herp', 'derp', 'wamp')) + , array('wamp', array('wamp'), array('wamp')) ); }