DummyGetResponsePlugin.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Connector\Sabre;
  8. use OCP\AppFramework\Http;
  9. use Sabre\DAV\Server;
  10. use Sabre\HTTP\RequestInterface;
  11. use Sabre\HTTP\ResponseInterface;
  12. /**
  13. * Class DummyGetResponsePlugin is a plugin used to not show a "Not implemented"
  14. * error to clients that rely on verifying the functionality of the Nextcloud
  15. * WebDAV backend using a simple GET to /.
  16. *
  17. * This is considered a legacy behaviour and implementers should consider sending
  18. * a PROPFIND request instead to verify whether the WebDAV component is working
  19. * properly.
  20. *
  21. * FIXME: Remove once clients are all compliant.
  22. *
  23. * @package OCA\DAV\Connector\Sabre
  24. */
  25. class DummyGetResponsePlugin extends \Sabre\DAV\ServerPlugin {
  26. protected ?Server $server = null;
  27. /**
  28. * @param \Sabre\DAV\Server $server
  29. * @return void
  30. */
  31. public function initialize(\Sabre\DAV\Server $server) {
  32. $this->server = $server;
  33. $this->server->on('method:GET', [$this, 'httpGet'], 200);
  34. }
  35. /**
  36. * @param RequestInterface $request
  37. * @param ResponseInterface $response
  38. * @return false
  39. */
  40. public function httpGet(RequestInterface $request, ResponseInterface $response) {
  41. $string = 'This is the WebDAV interface. It can only be accessed by ' .
  42. 'WebDAV clients such as the Nextcloud desktop sync client.';
  43. $stream = fopen('php://memory', 'r+');
  44. fwrite($stream, $string);
  45. rewind($stream);
  46. $response->setStatus(Http::STATUS_OK);
  47. $response->setBody($stream);
  48. return false;
  49. }
  50. }