Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2022-01-31 17:01:58 +0300
committerRobin Appelman <robin@icewind.nl>2022-02-01 16:24:01 +0300
commitc7129878780787151eae9edeb680b11c45535a34 (patch)
tree09e119b47dde3f04790103a35b0b017fbab16efa /apps/dav/lib/Connector
parentd635d58d19d5ab65c0be754fc32fce99672c249f (diff)
send request id in response header
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/dav/lib/Connector')
-rw-r--r--apps/dav/lib/Connector/Sabre/RequestIdHeaderPlugin.php49
-rw-r--r--apps/dav/lib/Connector/Sabre/ServerFactory.php3
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([