RequestIdHeaderPlugin.php 902 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\Connector\Sabre;
  8. use OCP\IRequest;
  9. use Sabre\HTTP\RequestInterface;
  10. use Sabre\HTTP\ResponseInterface;
  11. class RequestIdHeaderPlugin extends \Sabre\DAV\ServerPlugin {
  12. /** @var IRequest */
  13. private $request;
  14. public function __construct(IRequest $request) {
  15. $this->request = $request;
  16. }
  17. public function initialize(\Sabre\DAV\Server $server) {
  18. $server->on('afterMethod:*', [$this, 'afterMethod']);
  19. }
  20. /**
  21. * Add the request id as a header in the response
  22. *
  23. * @param RequestInterface $request request
  24. * @param ResponseInterface $response response
  25. */
  26. public function afterMethod(RequestInterface $request, ResponseInterface $response) {
  27. $response->setHeader('X-Request-Id', $this->request->getId());
  28. }
  29. }