public static function generate($request, $sid = null) { if (!$sid) { $sid = Utils::uid(24); } $request->sessionId = $sid; $request->session = new Session($request); }
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); } }