RequestIdHeaderPlugin.php 845 B

12345678910111213141516171819202122232425262728293031323334
  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. public function __construct(
  13. private IRequest $request,
  14. ) {
  15. }
  16. public function initialize(\Sabre\DAV\Server $server) {
  17. $server->on('afterMethod:*', [$this, 'afterMethod']);
  18. }
  19. /**
  20. * Add the request id as a header in the response
  21. *
  22. * @param RequestInterface $request request
  23. * @param ResponseInterface $response response
  24. */
  25. public function afterMethod(RequestInterface $request, ResponseInterface $response) {
  26. $response->setHeader('X-Request-Id', $this->request->getId());
  27. }
  28. }