DummyGetResponsePlugin.php 1.6 KB

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