镜像自地址
https://github.com/nextcloud/server.git
已同步 2024-07-21 12:00:37 +02:00
send request id in response header
Signed-off-by: Robin Appelman <robin@icewind.nl>
这个提交包含在:
父节点
d635d58d19
当前提交
c712987878
@ -169,6 +169,7 @@ return array(
|
||||
'OCA\\DAV\\Connector\\Sabre\\Principal' => $baseDir . '/../lib/Connector/Sabre/Principal.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\PropfindCompressionPlugin' => $baseDir . '/../lib/Connector/Sabre/PropfindCompressionPlugin.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\QuotaPlugin' => $baseDir . '/../lib/Connector/Sabre/QuotaPlugin.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\RequestIdHeaderPlugin' => $baseDir . '/../lib/Connector/Sabre/RequestIdHeaderPlugin.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\Server' => $baseDir . '/../lib/Connector/Sabre/Server.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\ServerFactory' => $baseDir . '/../lib/Connector/Sabre/ServerFactory.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\ShareTypeList' => $baseDir . '/../lib/Connector/Sabre/ShareTypeList.php',
|
||||
|
@ -184,6 +184,7 @@ class ComposerStaticInitDAV
|
||||
'OCA\\DAV\\Connector\\Sabre\\Principal' => __DIR__ . '/..' . '/../lib/Connector/Sabre/Principal.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\PropfindCompressionPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/PropfindCompressionPlugin.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\QuotaPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/QuotaPlugin.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\RequestIdHeaderPlugin' => __DIR__ . '/..' . '/../lib/Connector/Sabre/RequestIdHeaderPlugin.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\Server' => __DIR__ . '/..' . '/../lib/Connector/Sabre/Server.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\ServerFactory' => __DIR__ . '/..' . '/../lib/Connector/Sabre/ServerFactory.php',
|
||||
'OCA\\DAV\\Connector\\Sabre\\ShareTypeList' => __DIR__ . '/..' . '/../lib/Connector/Sabre/ShareTypeList.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());
|
||||
}
|
||||
}
|
@ -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([
|
||||
|
@ -34,6 +34,7 @@
|
||||
*/
|
||||
namespace OCA\DAV;
|
||||
|
||||
use OCA\DAV\Connector\Sabre\RequestIdHeaderPlugin;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use OCA\DAV\AppInfo\PluginManager;
|
||||
use OCA\DAV\CalDAV\BirthdayService;
|
||||
@ -205,6 +206,7 @@ class Server {
|
||||
));
|
||||
|
||||
$this->server->addPlugin(new CopyEtagHeaderPlugin());
|
||||
$this->server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class)));
|
||||
$this->server->addPlugin(new ChunkingPlugin());
|
||||
|
||||
// allow setup of additional plugins
|
||||
|
@ -33,6 +33,7 @@ namespace OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
@ -94,6 +95,12 @@ class Response {
|
||||
* @since 17.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
/** @var IRequest $request */
|
||||
/**
|
||||
* @psalm-suppress UndefinedClass
|
||||
*/
|
||||
$request = \OC::$server->get(IRequest::class);
|
||||
$this->addHeader("X-Request-Id", $request->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,6 +28,7 @@ use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
|
||||
class ChildController extends Controller {
|
||||
public function __construct($appName, $request) {
|
||||
@ -59,6 +60,7 @@ class ControllerTest extends \Test\TestCase {
|
||||
*/
|
||||
private $controller;
|
||||
private $app;
|
||||
private $request;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
@ -90,6 +92,8 @@ class ControllerTest extends \Test\TestCase {
|
||||
->willReturn('apptemplate_advanced');
|
||||
|
||||
$this->controller = new ChildController($this->app, $request);
|
||||
$this->overwriteService(IRequest::class, $request);
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
|
||||
@ -114,6 +118,7 @@ class ControllerTest extends \Test\TestCase {
|
||||
'Content-Type' => 'application/json; charset=utf-8',
|
||||
'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'",
|
||||
'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'",
|
||||
'X-Request-Id' => $this->request->getId(),
|
||||
'X-Robots-Tag' => 'none',
|
||||
];
|
||||
|
||||
|
@ -25,6 +25,7 @@ namespace Test\AppFramework\Http;
|
||||
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IRequest;
|
||||
|
||||
class DataResponseTest extends \Test\TestCase {
|
||||
|
||||
@ -68,6 +69,7 @@ class DataResponseTest extends \Test\TestCase {
|
||||
'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'",
|
||||
'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'",
|
||||
'X-Robots-Tag' => 'none',
|
||||
'X-Request-Id' => \OC::$server->get(IRequest::class)->getId(),
|
||||
];
|
||||
$expectedHeaders = array_merge($expectedHeaders, $headers);
|
||||
|
||||
|
@ -91,7 +91,7 @@ class ResponseTest extends \Test\TestCase {
|
||||
public function testAddHeaderValueNullDeletesIt() {
|
||||
$this->childResponse->addHeader('hello', 'world');
|
||||
$this->childResponse->addHeader('hello', null);
|
||||
$this->assertEquals(4, count($this->childResponse->getHeaders()));
|
||||
$this->assertEquals(5, count($this->childResponse->getHeaders()));
|
||||
}
|
||||
|
||||
|
||||
|
正在加载...
在新工单中引用
屏蔽一个用户