dummygetresponseplugin.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @author Lukas Reschke <lukas@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OC\Connector\Sabre;
  22. use Sabre\HTTP\ResponseInterface;
  23. use Sabre\HTTP\RequestInterface;
  24. /**
  25. * Class DummyGetResponsePlugin is a plugin used to not show a "Not implemented"
  26. * error to clients that rely on verifying the functionality of the ownCloud
  27. * WebDAV backend using a simple GET to /.
  28. *
  29. * This is considered a legacy behaviour and implementers should consider sending
  30. * a PROPFIND request instead to verify whether the WebDAV component is working
  31. * properly.
  32. *
  33. * FIXME: Remove once clients are all compliant.
  34. *
  35. * @package OC\Connector\Sabre
  36. */
  37. class DummyGetResponsePlugin extends \Sabre\DAV\ServerPlugin {
  38. /** @var \Sabre\DAV\Server */
  39. protected $server;
  40. /**
  41. * @param \Sabre\DAV\Server $server
  42. * @return void
  43. */
  44. function initialize(\Sabre\DAV\Server $server) {
  45. $this->server = $server;
  46. $this->server->on('method:GET', [$this, 'httpGet'], 200);
  47. }
  48. /**
  49. * @param RequestInterface $request
  50. * @param ResponseInterface $response
  51. * @return false
  52. */
  53. function httpGet(RequestInterface $request, ResponseInterface $response) {
  54. $string = 'This is the WebDAV interface. It can only be accessed by ' .
  55. 'WebDAV clients such as the ownCloud desktop sync client.';
  56. $stream = fopen('php://memory','r+');
  57. fwrite($stream, $string);
  58. rewind($stream);
  59. $response->setBody($stream);
  60. return false;
  61. }
  62. }