diff options
author | Robin Appelman <robin@icewind.nl> | 2022-01-31 17:01:58 +0300 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2022-02-01 16:24:01 +0300 |
commit | c7129878780787151eae9edeb680b11c45535a34 (patch) | |
tree | 09e119b47dde3f04790103a35b0b017fbab16efa /apps/dav/lib/Connector/Sabre | |
parent | d635d58d19d5ab65c0be754fc32fce99672c249f (diff) |
send request id in response header
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/dav/lib/Connector/Sabre')
-rw-r--r-- | apps/dav/lib/Connector/Sabre/RequestIdHeaderPlugin.php | 49 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/ServerFactory.php | 3 |
2 files changed, 52 insertions, 0 deletions
diff --git a/apps/dav/lib/Connector/Sabre/RequestIdHeaderPlugin.php b/apps/dav/lib/Connector/Sabre/RequestIdHeaderPlugin.php new file mode 100644 index 00000000000..b281a1053b8 --- /dev/null +++ b/apps/dav/lib/Connector/Sabre/RequestIdHeaderPlugin.php @@ -0,0 +1,49 @@ +<?php declare(strict_types=1); +/** + * @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\DAV\Connector\Sabre; + +use OCP\IRequest; +use Sabre\HTTP\RequestInterface; +use Sabre\HTTP\ResponseInterface; + +class RequestIdHeaderPlugin extends \Sabre\DAV\ServerPlugin { + /** @var IRequest */ + private $request; + + public function __construct(IRequest $request) { + $this->request = $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()); + } +} diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php index 7be24014881..ff96b7a19c5 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -130,6 +130,9 @@ class ServerFactory { $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); + + $server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class))); + // Some WebDAV clients do require Class 2 WebDAV support (locking), since // we do not provide locking we emulate it using a fake locking plugin. if ($this->request->isUserAgent([ |