nextcloud-raw/lib/Controller/ RawResponse.php
26 lines
724 B

  1. <?php
  2. namespace OCA\Raw\Controller;
  3. use \Exception;
  4. trait RawResponse {
  5. protected function returnRawResponse($fileNode) {
  6. if ($fileNode->getType() === 'dir') {
  7. // Is there some reasonable thing to return for a directory? An html index? A tarball?
  8. throw new Exception("Requested share is a directory, not a file.");
  9. }
  10. $content = $fileNode->getContent();
  11. $mimetype = $fileNode->getMimeType();
  12. // Ugly hack to prevent security middleware messing up the CSP.
  13. header(
  14. "Content-Security-Policy: sandbox; default-src 'none'; img-src data:; media-src data:; "
  15. . "style-src data: 'unsafe-inline'; font-src data:; frame-src data:"
  16. );
  17. header("Content-Type: ${mimetype}");
  18. echo $content;
  19. exit;
  20. }
  21. }