diff options
author | Robin Appelman <robin@icewind.nl> | 2023-04-20 15:26:37 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2023-04-28 15:37:57 +0200 |
commit | e7ab30f5d8da574979f4c5b233f0cbd6827ecd90 (patch) | |
tree | dfdc5aabfdd50e81d4617ec96c9c504a22bf3687 /lib/private/Http | |
parent | 74f31bac8c0473f3dc92fcb54967f4cf977c413f (diff) | |
download | nextcloud-server-e7ab30f5d8da574979f4c5b233f0cbd6827ecd90.tar.gz nextcloud-server-e7ab30f5d8da574979f4c5b233f0cbd6827ecd90.zip |
log performance events for http requests
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Http')
-rw-r--r-- | lib/private/Http/Client/ClientService.php | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/private/Http/Client/ClientService.php b/lib/private/Http/Client/ClientService.php index bbc2330176f..d0640680124 100644 --- a/lib/private/Http/Client/ClientService.php +++ b/lib/private/Http/Client/ClientService.php @@ -29,11 +29,14 @@ namespace OC\Http\Client; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\HandlerStack; use GuzzleHttp\Handler\CurlHandler; +use GuzzleHttp\Middleware; +use OCP\Diagnostics\IEventLogger; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\ICertificateManager; use OCP\IConfig; use OCP\Security\IRemoteHostValidator; +use Psr\Http\Message\RequestInterface; /** * Class ClientService @@ -48,15 +51,20 @@ class ClientService implements IClientService { /** @var DnsPinMiddleware */ private $dnsPinMiddleware; private IRemoteHostValidator $remoteHostValidator; + private IEventLogger $eventLogger; - public function __construct(IConfig $config, - ICertificateManager $certificateManager, - DnsPinMiddleware $dnsPinMiddleware, - IRemoteHostValidator $remoteHostValidator) { + public function __construct( + IConfig $config, + ICertificateManager $certificateManager, + DnsPinMiddleware $dnsPinMiddleware, + IRemoteHostValidator $remoteHostValidator, + IEventLogger $eventLogger, + ) { $this->config = $config; $this->certificateManager = $certificateManager; $this->dnsPinMiddleware = $dnsPinMiddleware; $this->remoteHostValidator = $remoteHostValidator; + $this->eventLogger = $eventLogger; } /** @@ -66,6 +74,11 @@ class ClientService implements IClientService { $handler = new CurlHandler(); $stack = HandlerStack::create($handler); $stack->push($this->dnsPinMiddleware->addDnsPinning()); + $stack->push(Middleware::tap(function (RequestInterface $request) { + $this->eventLogger->start('http:request', $request->getMethod() . " request to " . $request->getRequestTarget()); + }, function () { + $this->eventLogger->end('http:request'); + }), 'event logger'); $client = new GuzzleClient(['handler' => $stack]); |