Beispiel #1
0
 function __construct(HttpRequest $request)
 {
     $this->request = $request;
     $this->headers = RequestHeaders::fromHttpRequest($request);
     $this->query = $request->getQuery();
     // forward the events data, end, close
     Utils::forwardEvents($this, $request, array('pipe', 'data', 'close', 'error'));
     $request->on('end', function () {
         if (!$this->ended) {
             $this->ended = true;
             $this->emit('end');
         }
     });
     // we need to determine when a request has ended since React\Http\Server
     // doesn't do it for us
     if ($this->expectsBody()) {
         $total_length = $this->getContentLength();
         if ($total_length != null) {
             $seen_length = 0;
             $request->on('data', function ($data) use($total_length, &$seen_length) {
                 $seen_length += strlen($data);
                 if ($seen_length >= $total_length) {
                     // TODO: should we wait for the next tick in the event loop?
                     $this->ended = true;
                     $this->emit('end');
                 }
             });
         }
     }
 }
Beispiel #2
0
 function __construct(HttpResponse $http_response, Request $request)
 {
     $this->request = $request;
     $this->response = $http_response;
     $this->headers = new ResponseHeaders(200, 'Success');
     Utils::forwardEvents($this, $http_response, array('error', 'end', 'drain'));
     $date = new \DateTime('now');
     $this->setHeader('Date', $date->format(\DateTime::RFC1123));
 }