Skip to content

Commit

Permalink
Add support for Sec-WebSocket-Protocol header
Browse files Browse the repository at this point in the history
  • Loading branch information
bcosca authored and nanawel committed Sep 15, 2018
1 parent 27e7b00 commit 0261432
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions cli/ws.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0261432

Please sign in to comment.