mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-30 02:37:58 +08:00
doc: Add docs about fetching request object in socket.io callback. (#2454)
This commit is contained in:
parent
8a5e422a97
commit
567ebaa1fd
@ -393,7 +393,7 @@ return [
|
||||
];
|
||||
```
|
||||
|
||||
## Auth 鉴权
|
||||
### Auth 鉴权
|
||||
|
||||
您可以通过使用中间件来拦截 WebSocket 握手,实现鉴权功能,如下:
|
||||
|
||||
@ -435,3 +435,16 @@ class WebSocketAuthMiddleware implements MiddlewareInterface
|
||||
```
|
||||
|
||||
并将上面的中间件配置到对应的 WebSocket Server 中去即可。
|
||||
|
||||
### 获取原始请求对象
|
||||
|
||||
连接建立以后,有时需获取客户端 IP ,Cookie 等请求信息。原始请求对象已经被保留在[连接上下文](websocket-server.md#连接上下文)中,您可以用如下方式在事件回调中获取:
|
||||
|
||||
```php
|
||||
public function onEvent($socket, $data)
|
||||
{
|
||||
$request = Hyperf\WebSocketServer\Context::get(
|
||||
Psr\Http\Message\ServerRequestInterface::class
|
||||
);
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user