From d11efb21b285d45b9b08cdbcd0b303433dde769f Mon Sep 17 00:00:00 2001 From: Yurun Date: Fri, 3 Jan 2020 09:48:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8F=A1=E6=89=8B=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E8=BF=94=E5=9B=9E=E5=90=8E=E5=86=99=E5=85=A5=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E4=B8=8A=E4=B8=8B=E6=96=87=EF=BC=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=9C=89=E6=97=B6=E5=88=9A=E6=8F=A1=E6=89=8B=E5=AE=8C=20WebSoc?= =?UTF-8?q?ket=20=E9=80=9A=E8=AE=AF=E8=8E=B7=E5=8F=96=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E6=95=B0=E6=8D=AE=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WebSocket/Listener/BeforeHandShake.php | 20 +------------------ .../Middleware/HandShakeMiddleware.php | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/Server/WebSocket/Listener/BeforeHandShake.php b/src/Server/WebSocket/Listener/BeforeHandShake.php index 6ce72d2b06..24d920cc1b 100644 --- a/src/Server/WebSocket/Listener/BeforeHandShake.php +++ b/src/Server/WebSocket/Listener/BeforeHandShake.php @@ -43,25 +43,7 @@ public function handle(HandShakeEventParam $e) // 中间件 $dispatcher = RequestContext::getServerBean('HttpDispatcher'); - $response = $dispatcher->dispatch($e->request, $e->response); - if(StatusCode::SWITCHING_PROTOCOLS === $response->getStatusCode()) - { - // http 路由解析结果 - $routeResult = RequestContext::get('routeResult'); - $routeResult->routeItem->callable = null; - $routeResult->callable = null; - ConnectContext::muiltiSet([ - 'httpRouteResult' => $routeResult, - 'uri' => $e->request->getUri(), - ]); - - $server = $e->getTarget(); - $request = $e->request; - $server->trigger('open', [ - 'server' => &$server, - 'request' => &$request, - ], $this, OpenEventParam::class); - } + $dispatcher->dispatch($e->request, $e->response); } } \ No newline at end of file diff --git a/src/Server/WebSocket/Middleware/HandShakeMiddleware.php b/src/Server/WebSocket/Middleware/HandShakeMiddleware.php index 5f0b32bf98..622c92df5e 100644 --- a/src/Server/WebSocket/Middleware/HandShakeMiddleware.php +++ b/src/Server/WebSocket/Middleware/HandShakeMiddleware.php @@ -1,10 +1,13 @@ defaultHandShake($request, $response); } + if(StatusCode::SWITCHING_PROTOCOLS === $response->getStatusCode()) + { + // http 路由解析结果 + $routeResult = RequestContext::get('routeResult'); + $routeResult->routeItem->callable = null; + $routeResult->callable = null; + ConnectContext::muiltiSet([ + 'httpRouteResult' => $routeResult, + 'uri' => $request->getUri(), + ]); + + $server = RequestContext::get('server'); + $server->trigger('open', [ + 'server' => &$server, + 'request' => &$request, + ], $this, OpenEventParam::class); + } return $response; }