Fixed sub-protocol handling

This commit is contained in:
Chris Boden 2015-05-31 15:43:58 -04:00
parent e45cd158bd
commit d8babac7e7

View File

@ -80,8 +80,9 @@ class Negotiator implements NegotiatorInterface {
} }
$headers = []; $headers = [];
if (count($this->_supportedSubProtocols) > 0) {
$subProtocols = $request->getHeader('Sec-WebSocket-Protocol'); $subProtocols = $request->getHeader('Sec-WebSocket-Protocol');
if (count($subProtocols) > 0 || (count($this->_supportedSubProtocols) > 0 && $this->_strictSubProtocols)) {
$subProtocols = array_map('trim', explode(',', implode(',', $subProtocols)));
$match = array_reduce($subProtocols, function($accumulator, $protocol) { $match = array_reduce($subProtocols, function($accumulator, $protocol) {
return $accumulator ?: (isset($this->_supportedSubProtocols[$protocol]) ? $protocol : null); return $accumulator ?: (isset($this->_supportedSubProtocols[$protocol]) ? $protocol : null);
@ -91,8 +92,10 @@ class Negotiator implements NegotiatorInterface {
return new Response(400, [], '1.1', null ,'No Sec-WebSocket-Protocols requested supported'); return new Response(400, [], '1.1', null ,'No Sec-WebSocket-Protocols requested supported');
} }
if (null !== $match) {
$headers['Sec-WebSocket-Protocol'] = $match; $headers['Sec-WebSocket-Protocol'] = $match;
} }
}
return new Response(101, array_merge($headers, [ return new Response(101, array_merge($headers, [
'Upgrade' => 'websocket' 'Upgrade' => 'websocket'