Signed-off-by: Robin Appelman <robin@icewind.nl>pull/57191/head
parent
154f3597b4
commit
69249a3ce3
@ -0,0 +1,36 @@ |
||||
<?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\IUserSession; |
||||
use Sabre\HTTP\RequestInterface; |
||||
use Sabre\HTTP\ResponseInterface; |
||||
|
||||
class UserIdHeaderPlugin extends \Sabre\DAV\ServerPlugin { |
||||
public function __construct( |
||||
private readonly IUserSession $userSession, |
||||
) { |
||||
} |
||||
|
||||
public function initialize(\Sabre\DAV\Server $server): void { |
||||
$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): void { |
||||
if ($user = $this->userSession->getUser()) { |
||||
$response->setHeader('X-User-Id', $user->getUID()); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue