doc: Add docs about fetching request object in socket.io callback. (#2454)

This commit is contained in:
谷溪 2020-09-07 15:38:17 +08:00 committed by GitHub
parent 8a5e422a97
commit 567ebaa1fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
);
}
```