public function getDocument(Path $path, Request $request, TokenInfo $tokenInfo = null) { if (null !== $tokenInfo) { if ($path->getUserId() !== $tokenInfo->getUserId()) { throw new ForbiddenException('path does not match authorized subject'); } if (!$this->hasReadScope($tokenInfo->getScope(), $path->getModuleName())) { throw new ForbiddenException('path does not match authorized scope'); } } $documentVersion = $this->remoteStorage->getVersion($path); if (null === $documentVersion) { throw new NotFoundException(sprintf('document "%s" not found', $path->getPath())); } $requestedVersion = $this->stripQuotes($request->getHeader('If-None-Match')); $documentContentType = $this->remoteStorage->getContentType($path); if (null !== $requestedVersion) { if (in_array($documentVersion, $requestedVersion)) { $response = new Response(304, $documentContentType); $response->setHeader('ETag', '"' . $documentVersion . '"'); return $response; } } $rsr = new Response(200, $documentContentType); $rsr->setHeader('ETag', '"' . $documentVersion . '"'); if ('development' !== $this->options['server_mode']) { $rsr->setHeader('Accept-Ranges', 'bytes'); } if ('GET' === $request->getMethod()) { if ('development' === $this->options['server_mode']) { // use body $rsr->setBody(file_get_contents($this->remoteStorage->getDocument($path, $requestedVersion))); } else { // use X-SendFile $rsr->setFile($this->remoteStorage->getDocument($path, $requestedVersion)); } } return $rsr; }