From 02614322cfcfb14263043165dc19ddddaca8335c Mon Sep 17 00:00:00 2001 From: Bong Cosca Date: Tue, 31 Jul 2018 03:05:43 +0000 Subject: [PATCH] Add support for Sec-WebSocket-Protocol header --- cli/ws.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/cli/ws.php b/cli/ws.php index c11e8add..f38fc81f 100644 --- a/cli/ws.php +++ b/cli/ws.php @@ -105,20 +105,21 @@ function alloc($socket) { return; } // Handshake - $bytes=$this->write( - $socket, - $str='HTTP/1.1 101 Switching Protocols'.$CRLF. - 'Upgrade: websocket'.$CRLF. - 'Connection: Upgrade'.$CRLF. - 'Sec-WebSocket-Accept: '. - base64_encode( - sha1( - $hdrs['Sec-Websocket-Key']. - self::Magic, - TRUE - ) - ).$CRLF.$CRLF - ); + $str='HTTP/1.1 101 Switching Protocols'.$CRLF. + 'Upgrade: websocket'.$CRLF. + 'Connection: Upgrade'.$CRLF; + if (isset($hdrs['Sec-Websocket-Protocol'])) + $str.='Sec-WebSocket-Protocol: '. + $hdrs['Sec-Websocket-Protocol'].$CRLF; + $str.='Sec-WebSocket-Accept: '. + base64_encode( + sha1( + $hdrs['Sec-Websocket-Key']. + self::Magic, + TRUE + ) + ).$CRLF.$CRLF; + $bytes=$this->write($socket,$str); if ($bytes) { // Connect agent to server $this->sockets[]=$socket;