Example #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');
                 }
             });
         }
     }
 }
Example #2
0
 public static function generate($request, $sid = null)
 {
     if (!$sid) {
         $sid = Utils::uid(24);
     }
     $request->sessionId = $sid;
     $request->session = new Session($request);
 }
Example #3
0
 function __construct($value, $options = array())
 {
     $this->value = (string) $value;
     $this->http_only = Utils::array_val($options, 'http_only', $this->http_only);
     $this->secure = Utils::array_val($options, 'secure', $this->secure);
     $this->domain = Utils::array_val($options, 'domain', $this->domain);
     $this->path = Utils::array_val($options, 'path', $this->path);
     $this->max_age = Utils::array_val($options, 'max_age', $this->max_age);
 }
Example #4
0
 public function send()
 {
     $handle = fopen($this->path, 'r');
     $info = fstat($handle);
     $size = $info['size'];
     $modifiedDate = \DateTime::createFromFormat('U', $info['mtime']);
     if (!$this->validRanges($size)) {
         $this->response->setStatus(416);
         $this->response->setHeader('Content-Range', '*/' . $size);
         $this->response->end();
         return;
     }
     $this->response->setStatus(206);
     $this->response->setHeader('Last-Modified', $modifiedDate->format(\DateTime::RFC1123));
     $this->response->on('end', function () use($handle) {
         fclose($handle);
     });
     // if a single range is requested then response is not multipart
     if (count($this->ranges) == 1) {
         $range = $this->ranges[0];
         $boundary = $range->boundaryForSize($size);
         $this->response->setHeader('Content-Range', "{$boundary['0']}-{$boundary['1']}/{$size}");
         $this->response->setHeader('Content-Length', $boundary[1] + 1 - $boundary[0]);
         $this->response->sendHeaders(206);
         $part = new RangePart($this->response, $this->content_type, null, $handle, $range);
         $part->once('end', function () {
             $this->response->end();
         });
         $part->send(true);
     } else {
         // multipart
         $boundary = 'PHLUID-BRS-' . Utils::uid(24);
         $this->response->setHeader('Content-Type', "multipart/byteranges; boundary={$boundary}");
         $parts = RangePart::partsFromRanges($this->response, $this->content_type, $boundary, $handle, $this->ranges);
         $contentLength = $this->contentLengthForParts($parts);
         $contentLength += strlen("--{$boundary}--");
         $this->response->sendHeaders(206, array('Content-Length' => $contentLength));
         $this->writeParts($parts, $boundary);
     }
 }
Example #5
0
 public function render($template, $locals = array(), $options = array())
 {
     $layout = Utils::array_val($options, 'layout', $this->options['default_layout']);
     $status = Utils::array_val($options, 'status', 200);
     $content_type = Utils::array_val($options, 'content-type', 'text/html');
     $locals['request'] = $this->request;
     $view = new View($template, $layout, $this->options['view_path']);
     $this->renderText($view->render($locals), $content_type, $status);
 }