summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/Http/Client/ClientService.php21
-rw-r--r--tests/lib/Http/Client/ClientServiceTest.php12
2 files changed, 28 insertions, 5 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]);
diff --git a/tests/lib/Http/Client/ClientServiceTest.php b/tests/lib/Http/Client/ClientServiceTest.php
index ed1165236aa..72281a0453c 100644
--- a/tests/lib/Http/Client/ClientServiceTest.php
+++ b/tests/lib/Http/Client/ClientServiceTest.php
@@ -14,12 +14,15 @@ namespace Test\Http\Client;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
+use GuzzleHttp\Middleware;
use OC\Http\Client\Client;
use OC\Http\Client\ClientService;
use OC\Http\Client\DnsPinMiddleware;
+use OCP\Diagnostics\IEventLogger;
use OCP\ICertificateManager;
use OCP\IConfig;
use OCP\Security\IRemoteHostValidator;
+use Psr\Http\Message\RequestInterface;
/**
* Class ClientServiceTest
@@ -37,17 +40,24 @@ class ClientServiceTest extends \Test\TestCase {
->willReturn(function () {
});
$remoteHostValidator = $this->createMock(IRemoteHostValidator::class);
+ $eventLogger = $this->createMock(IEventLogger::class);
$clientService = new ClientService(
$config,
$certificateManager,
$dnsPinMiddleware,
- $remoteHostValidator
+ $remoteHostValidator,
+ $eventLogger
);
$handler = new CurlHandler();
$stack = HandlerStack::create($handler);
$stack->push($dnsPinMiddleware->addDnsPinning());
+ $stack->push(Middleware::tap(function (RequestInterface $request) use ($eventLogger) {
+ $eventLogger->start('http:request', $request->getMethod() . " request to " . $request->getRequestTarget());
+ }, function () use ($eventLogger) {
+ $eventLogger->end('http:request');
+ }), 'event logger');
$guzzleClient = new GuzzleClient(['handler' => $stack]);
$this->assertEquals(