Skip to content

Commit c2cefcc

Browse files
authored
Merge pull request #59530 from SMillerDev/feat/http/psr-18
feat: Implement PSR-18 ClientInterface in IClient
2 parents 7e1401a + 769198b commit c2cefcc

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/private/Http/Client/Client.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use OCP\IConfig;
2020
use OCP\Security\IRemoteHostValidator;
2121
use OCP\ServerVersion;
22+
use Psr\Http\Message\RequestInterface;
23+
use Psr\Http\Message\ResponseInterface;
2224
use Psr\Log\LoggerInterface;
2325
use function parse_url;
2426

@@ -477,6 +479,11 @@ public function request(string $method, string $uri, array $options = []): IResp
477479
return new Response($response, $isStream);
478480
}
479481

482+
public function sendRequest(RequestInterface $request): ResponseInterface {
483+
$this->preventLocalAddress((string)$request->getUri(), []);
484+
return $this->client->sendRequest($request);
485+
}
486+
480487
protected function wrapGuzzlePromise(PromiseInterface $promise): IPromise {
481488
return new GuzzlePromiseAdapter(
482489
$promise,

lib/public/Http/Client/IClient.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
*/
99
namespace OCP\Http\Client;
1010

11+
use Psr\Http\Client\ClientInterface;
12+
use Psr\Http\Message\RequestInterface;
13+
use Psr\Http\Message\ResponseInterface;
14+
1115
/**
1216
* Interface IClient
1317
*
1418
* @since 8.1.0
1519
*/
16-
interface IClient {
20+
interface IClient extends ClientInterface {
1721

1822
/**
1923
* Default request timeout for requests
@@ -268,6 +272,18 @@ public function getResponseFromThrowable(\Throwable $e): IResponse;
268272
*/
269273
public function request(string $method, string $uri, array $options = []): IResponse;
270274

275+
/**
276+
* Sends a PSR-7 request and returns a PSR-7 response, part of the PSR-18 interface.
277+
*
278+
* @param RequestInterface $request PSR-7 request interface
279+
*
280+
* @return ResponseInterface PSR-7 response interface
281+
*
282+
* @throws \Psr\Http\Client\ClientExceptionInterface If an error happens while processing the request.
283+
* @since 34.0.0
284+
*/
285+
public function sendRequest(RequestInterface $request): ResponseInterface;
286+
271287
/**
272288
* Sends an asynchronous GET request
273289
* @param string $uri

0 commit comments

Comments
 (0)