Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to retrieve cookie from $request parametr if it's a string? #954

Open
shizzic opened this issue Sep 25, 2023 · 1 comment
Open

How to retrieve cookie from $request parametr if it's a string? #954

shizzic opened this issue Sep 25, 2023 · 1 comment

Comments

@shizzic
Copy link

shizzic commented Sep 25, 2023

I have this example

$this->worker = new Worker('websocket://0.0.0.0:8090', $this->context);
        $this->worker->name = 'websocket';
        $this->worker->count     = 1;
        $this->worker->transport = 'ssl';

        $this->worker->onConnect = function($connection) {
            $connection->onWebSocketConnect = function ($connection, $request) {
                $connection->send($request);
            };
        };

And when i'm trying to use any method on $request like $request->cookie() i keep getting error like "Error: Call to a member function cookie() on string". Is there a build in parser for request or do i need to handle it myself?
When i worked with SSE, $request seems to be normal (not string).

@Chance-fyi
Copy link
Contributor

What's your version of workerman?
The parameters passed to onWebSocketConnect are not the same for 4.x and 5.x versions.

4.x

// Try to emit onWebSocketConnect callback.
$on_websocket_connect = $connection->onWebSocketConnect ?? $connection->worker->onWebSocketConnect ?? false;
if ($on_websocket_connect) {
static::parseHttpHeader($buffer);
try {
\call_user_func($on_websocket_connect, $connection, $buffer);
} catch (\Exception $e) {
Worker::stopAll(250, $e);
} catch (\Error $e) {
Worker::stopAll(250, $e);
}
if (!empty($_SESSION) && \class_exists('\GatewayWorker\Lib\Context')) {
$connection->session = \GatewayWorker\Lib\Context::sessionEncode($_SESSION);
}
$_GET = $_SERVER = $_SESSION = $_COOKIE = array();
}

5.x

// Try to emit onWebSocketConnect callback.
$onWebsocketConnect = $connection->onWebSocketConnect ?? $connection->worker->onWebSocketConnect ?? false;
if ($onWebsocketConnect) {
try {
$onWebsocketConnect($connection, new Request($buffer));
} catch (Throwable $e) {
Worker::stopAll(250, $e);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants