From fe567bc3e4de4807c81a6e6f2698e7f9e51bfdd6 Mon Sep 17 00:00:00 2001 From: Dima Efimenko Date: Tue, 8 Dec 2015 00:58:35 +0300 Subject: [PATCH 1/2] WebSocket/Route: fix setcookie --- PHPDaemon/WebSocket/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PHPDaemon/WebSocket/Route.php b/PHPDaemon/WebSocket/Route.php index 3910c0d0..e8641636 100644 --- a/PHPDaemon/WebSocket/Route.php +++ b/PHPDaemon/WebSocket/Route.php @@ -68,7 +68,7 @@ protected function getSessionState() { * @return void */ public function setcookie($name, $value = '', $maxage = 0, $path = '', $domain = '', $secure = false, $HTTPOnly = false) { - $this->header( + $this->client->header( 'Set-Cookie: ' . $name . '=' . rawurlencode($value) . (empty($domain) ? '' : '; Domain=' . $domain) . (empty($maxage) ? '' : '; Max-Age=' . $maxage) From fe748238c3903dab2be2355c83a5a0416f06cc1b Mon Sep 17 00:00:00 2001 From: Dima Efimenko Date: Tue, 8 Dec 2015 00:59:08 +0300 Subject: [PATCH 2/2] Servers/WebSocket: call onBeforeHandshake before getHandshakeReply --- PHPDaemon/Servers/WebSocket/Connection.php | 34 +++++++++------------- PHPDaemon/SockJS/WebSocketRouteProxy.php | 5 ++-- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/PHPDaemon/Servers/WebSocket/Connection.php b/PHPDaemon/Servers/WebSocket/Connection.php index cc914629..27d27827 100644 --- a/PHPDaemon/Servers/WebSocket/Connection.php +++ b/PHPDaemon/Servers/WebSocket/Connection.php @@ -249,6 +249,20 @@ public function handshake($extraHeaders = null) { return false; } + if ($extraHeaders === null && method_exists($this->route, 'onBeforeHandshake')) { + $this->route->onWakeup(); + $this->route->onBeforeHandshake(); + + $extraHeaders = ''; + foreach ($this->headers as $k => $line) { + if ($k !== 'STATUS') { + $extraHeaders .= $line . "\r\n"; + } + } + + $this->route->onSleep(); + } + // Handshaking... $handshake = $this->protocol->getHandshakeReply($this->buf, $extraHeaders); if ($handshake === 0) { // not enough data yet @@ -259,26 +273,6 @@ public function handshake($extraHeaders = null) { $this->finish(); return false; } - if ($extraHeaders === null && method_exists($this->route, 'onBeforeHandshake')) { - $this->route->onWakeup(); - $ret = $this->route->onBeforeHandshake(function($cb) { - $h = ''; - foreach ($this->headers as $k => $line) { - if ($k !== 'STATUS') { - $h .= $line . "\r\n"; - } - } - if ($this->handshake($h)) { - if ($cb !== null) { - call_user_func($cb); - } - } - }); - $this->route->onSleep(); - if ($ret !== false) { - return; - } - } if (!isset($this->protocol)) { Daemon::$process->log(get_class($this) . '::' . __METHOD__ . ' : Cannot find session-related websocket protocol for client "' . $this->addr . '"'); diff --git a/PHPDaemon/SockJS/WebSocketRouteProxy.php b/PHPDaemon/SockJS/WebSocketRouteProxy.php index 13ab39e6..acc12d4d 100755 --- a/PHPDaemon/SockJS/WebSocketRouteProxy.php +++ b/PHPDaemon/SockJS/WebSocketRouteProxy.php @@ -85,14 +85,13 @@ public function onPacket($frame, $type) { /** * realRoute onBeforeHandshake - * @param callable $cb * @return void|false */ - public function onBeforeHandshake($cb) { + public function onBeforeHandshake() { if (!method_exists($this->realRoute, 'onBeforeHandshake')) { return false; } - $this->realRoute->onBeforeHandshake($cb); + $this->realRoute->onBeforeHandshake(); } /**