Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/private/Http/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
use OCP\IConfig;
use OCP\Security\IRemoteHostValidator;
use OCP\ServerVersion;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
use function parse_url;

Expand Down Expand Up @@ -477,6 +479,21 @@ public function request(string $method, string $uri, array $options = []): IResp
return new Response($response, $isStream);
}

/**
* Sends a PSR-7 request and returns a PSR-7 response, part of the PSR-18 interface.
* This is a thin wrapper arround the Guzzle Client implementation
*
* @param RequestInterface $request PSR-7 request interface
*
* @return ResponseInterface PSR-7 response interface
*
* @throws \Psr\Http\Client\ClientExceptionInterface If an error happens while processing the request.
*/
public function sendRequest(RequestInterface $request): ResponseInterface {
$this->preventLocalAddress((string)$request->getUri(), []);
return $this->client->sendRequest($request);
}

protected function wrapGuzzlePromise(PromiseInterface $promise): IPromise {
return new GuzzlePromiseAdapter(
$promise,
Expand Down
17 changes: 16 additions & 1 deletion lib/public/Http/Client/IClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
*/
namespace OCP\Http\Client;

use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* Interface IClient
*
* @since 8.1.0
*/
interface IClient {
interface IClient extends ClientInterface {

/**
* Default request timeout for requests
Expand Down Expand Up @@ -268,6 +272,17 @@ public function getResponseFromThrowable(\Throwable $e): IResponse;
*/
public function request(string $method, string $uri, array $options = []): IResponse;

/**
* Sends a PSR-7 request and returns a PSR-7 response, part of the PSR-18 interface.
*
* @param RequestInterface $request PSR-7 request interface
*
* @return ResponseInterface PSR-7 response interface
*
* @throws \Psr\Http\Client\ClientExceptionInterface If an error happens while processing the request.
*/
public function sendRequest(RequestInterface $request): ResponseInterface;

/**
* Sends an asynchronous GET request
* @param string $uri
Expand Down
Loading