hyperf / hyperf/socketio-server

事件回调的连接上下文中获取不到原始请求对象

Open
#17 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
26
Forks
6
PR merge metrics
No merged PRs in 30d

Description

代码如下:
```
/**
* @Event("connect")
*/
public function onConnect(Socket $socket)
{
$request = \Hyperf\WebSocketServer\Context::get(
Psr\Http\Message\ServerRequestInterface::class
);
var_dump($request);
return;
}
```
打印结果为null,在`onHandShake`回调的`initRequest`方法中可以正常打印出结果
```
/**
* Initialize PSR-7 Request.
*/
protected function initRequest(SwooleRequest $request): ServerRequestInterface
{
Context::set(ServerRequestInterface::class, $psr7Request = Psr7Request::loadFromSwooleRequest($request));
WsContext::set(ServerRequestInterface::class, $psr7Request);
var_dump(WsContext::get(ServerRequestInterface::class));
return $psr7Request;
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by comparing the onConnect callback with the onHandShake initRequest method shown in the report, tracing where ServerRequestInterface is stored and retrieved from Context. Verify the callback lifecycle and reproduce the null value; done means the original request is available in the connect context or the issue clearly documents the supported limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.