aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Connector/Sabre/RequestIdHeaderPlugin.php
blob: 5484bab92370a6b4cf06cae60841dd7d86f62cad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

declare(strict_types=1);
/**
 * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

namespace OCA\DAV\Connector\Sabre;

use OCP\IRequest;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;

class RequestIdHeaderPlugin extends \Sabre\DAV\ServerPlugin {
	public function __construct(
		private IRequest $request,
	) {
	}

	public function initialize(\Sabre\DAV\Server $server) {
		$server->on('afterMethod:*', [$this, 'afterMethod']);
	}

	/**
	 * Add the request id as a header in the response
	 *
	 * @param RequestInterface $request request
	 * @param ResponseInterface $response response
	 */
	public function afterMethod(RequestInterface $request, ResponseInterface $response) {
		$response->setHeader('X-Request-Id', $this->request->getId());
	}
}