예제 #1
0
파일: Server.php 프로젝트: shsrain/ypyzApi
 public function handleRequest(ConnectionInterface $conn, Request $request, $bodyBuffer)
 {
     $response = new Response($conn);
     $response->on('close', array($request, 'close'));
     if (!$this->listeners('request')) {
         $response->end();
         return;
     }
     $this->emit('request', array($request, $response));
     $request->emit('data', array($bodyBuffer));
 }
예제 #2
0
 public function testResponseShouldEmitEndOnStreamEnd()
 {
     $ended = false;
     $conn = $this->getMock('React\\Socket\\ConnectionInterface');
     $response = new Response($conn);
     $response->on('end', function () use(&$ended) {
         $ended = true;
     });
     $response->end();
     $this->assertTrue($ended);
 }
예제 #3
0
 public function handle(Request $request, Response $response)
 {
     $headers = array_change_key_case($request->getHeaders(), CASE_LOWER);
     // Only enable when the X-Blackfire-Query header is present
     if (!isset($headers['x-blackfire-query'])) {
         return array();
     }
     $probe = new \BlackfireProbe($headers['x-blackfire-query']);
     // Stop if it failed
     if (!$probe->enable()) {
         return array();
     }
     // Stop profiling once the request ends
     $response->on('end', array($probe, 'close'));
     // Return the header
     $header = explode(':', $probe->getResponseLine(), 2);
     return array('x-' . $header[0] => $header[1]);
 }
예제 #4
0
파일: Server.php 프로젝트: thinframe/server
 /**
  * Handle HTTP request
  *
  * @param Request  $request
  * @param Response $response
  */
 public function handleRequest(Request $request, Response $response)
 {
     $this->logger->debug(sprintf("Inbound request: %s %s HTTP/%s", $request->getMethod(), $request->getPath(), $request->getHttpVersion()), ['request' => $request, 'response' => $response]);
     $request->pause();
     $resolver = new RequestResolver($request, $response, $this->dispatcher);
     $resolver->resolve();
     $response->on('end', 'gc_collect_cycles');
     $request->resume();
 }