收到请求事件

  1. function onRequest(Request $request,Response $response);

当easySwoole收到任何的HTTP请求时,均会执行该事件。该事件可以对HTTP请求全局拦截。

  1. $sec = new Security();
  2. if($sec->check($request->getRequestParam())){
  3. $response->write("do not attack");
  4. $response->end();
  5. return;
  6. }
  7. if($sec->check($request->getCookieParams())){
  8. $response->write("do not attack");
  9. $response->end();
  10. return;
  11. }

或者是

  1. $cookie = $request->getCookieParams('who');
  2. //do cookie auth
  3. if(auth fail){
  4. $response->end();
  5. return;
  6. }

若在改事件中,执行 $response->end(),则该次请求不会进入路由匹配阶段。