From 5d7a02b32c8aeea687e0cc3dc1d5558f4ac95121 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sun, 26 Apr 2026 13:39:09 +0200 Subject: [PATCH 1/2] feat: add ClientService configuration option Signed-off-by: Sean Molenaar --- lib/public/Http/Client/IClientService.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/public/Http/Client/IClientService.php b/lib/public/Http/Client/IClientService.php index 148757e5b3198..d64813bbbf2a9 100644 --- a/lib/public/Http/Client/IClientService.php +++ b/lib/public/Http/Client/IClientService.php @@ -14,9 +14,10 @@ * @since 8.1.0 */ interface IClientService { - /** - * @return IClient - * @since 8.1.0 - */ - public function newClient(): IClient; + /** + * @param array $baseConfig default configuration for the client + * @return IClient + * @since 8.1.0 + */ + public function newClient(array $baseConfig = []): IClient; } From 082c13739f389ab332696036d7e6f4221fe81fb7 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Sun, 26 Apr 2026 13:47:22 +0200 Subject: [PATCH 2/2] feat: implement config for newClient Signed-off-by: Sean Molenaar --- lib/private/Http/Client/ClientService.php | 5 +- lib/public/Http/Client/IClientService.php | 11 +++-- tests/lib/Http/Client/ClientServiceTest.php | 52 +++++++++++++++++++++ 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/lib/private/Http/Client/ClientService.php b/lib/private/Http/Client/ClientService.php index 1e40ef31bc153..027f17906014a 100644 --- a/lib/private/Http/Client/ClientService.php +++ b/lib/private/Http/Client/ClientService.php @@ -39,7 +39,7 @@ public function __construct( ) { } - public function newClient(): IClient { + public function newClient(array $baseConfig = []): IClient { $handler = new CurlHandler(); $stack = HandlerStack::create($handler); if ($this->config->getSystemValueBool('dns_pinning', true)) { @@ -51,7 +51,8 @@ public function newClient(): IClient { $this->eventLogger->end('http:request'); }), 'event logger'); - $client = new GuzzleClient(['handler' => $stack]); + $config = array_merge($baseConfig, ['handler' => $stack]); + $client = new GuzzleClient($config); return new Client( $this->config, diff --git a/lib/public/Http/Client/IClientService.php b/lib/public/Http/Client/IClientService.php index d64813bbbf2a9..d92c69c649e40 100644 --- a/lib/public/Http/Client/IClientService.php +++ b/lib/public/Http/Client/IClientService.php @@ -14,10 +14,11 @@ * @since 8.1.0 */ interface IClientService { - /** - * @param array $baseConfig default configuration for the client - * @return IClient - * @since 8.1.0 - */ + + /** + * @param array $baseConfig default configuration for the client + * @return IClient + * @since 8.1.0 + */ public function newClient(array $baseConfig = []): IClient; } diff --git a/tests/lib/Http/Client/ClientServiceTest.php b/tests/lib/Http/Client/ClientServiceTest.php index e7f116b9b6910..62b977d526418 100644 --- a/tests/lib/Http/Client/ClientServiceTest.php +++ b/tests/lib/Http/Client/ClientServiceTest.php @@ -81,6 +81,58 @@ public function testNewClient(): void { ); } + public function testNewClientWithConfig(): void { + /** @var IConfig $config */ + $config = $this->createMock(IConfig::class); + $config->method('getSystemValueBool') + ->with('dns_pinning', true) + ->willReturn(true); + /** @var ICertificateManager $certificateManager */ + $certificateManager = $this->createMock(ICertificateManager::class); + $dnsPinMiddleware = $this->createMock(DnsPinMiddleware::class); + $dnsPinMiddleware + ->expects($this->atLeastOnce()) + ->method('addDnsPinning') + ->willReturn(function (): void { + }); + $remoteHostValidator = $this->createMock(IRemoteHostValidator::class); + $eventLogger = $this->createMock(IEventLogger::class); + $logger = $this->createMock(LoggerInterface::class); + $serverVersion = $this->createMock(ServerVersion::class); + + $clientService = new ClientService( + $config, + $certificateManager, + $dnsPinMiddleware, + $remoteHostValidator, + $eventLogger, + $logger, + $serverVersion, + ); + + $handler = new CurlHandler(); + $stack = HandlerStack::create($handler); + $stack->push($dnsPinMiddleware->addDnsPinning()); + $stack->push(Middleware::tap(function (RequestInterface $request) use ($eventLogger): void { + $eventLogger->start('http:request', $request->getMethod() . ' request to ' . $request->getRequestTarget()); + }, function () use ($eventLogger): void { + $eventLogger->end('http:request'); + }), 'event logger'); + $guzzleClient = new GuzzleClient(['handler' => $stack, 'timeout' => 2.0]); + + $this->assertEquals( + new Client( + $config, + $certificateManager, + $guzzleClient, + $remoteHostValidator, + $logger, + $serverVersion, + ), + $clientService->newClient(['timeout' => 2.0]) + ); + } + public function testDisableDnsPinning(): void { /** @var IConfig $config */ $config = $this->createMock(IConfig::class);