feat(IClient): Add `request` function to do arbitrary HTTP requests

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/43939/head
Ferdinand Thiessen 3 months ago committed by Côme Chilliet
parent e17424fa11
commit 01d5af66be

@ -424,6 +424,43 @@ class Client implements IClient {
throw $e;
}
/**
* Sends a HTTP request
*
* @param string $uri
* @param string $method The HTTP method to use
* @param array $options Array such as
* 'query' => [
* 'field' => 'abc',
* 'other_field' => '123',
* 'file_name' => fopen('/path/to/file', 'r'),
* ],
* 'headers' => [
* 'foo' => 'bar',
* ],
* 'cookies' => [
* 'foo' => 'bar',
* ],
* 'allow_redirects' => [
* 'max' => 10, // allow at most 10 redirects.
* 'strict' => true, // use "strict" RFC compliant redirects.
* 'referer' => true, // add a Referer header
* 'protocols' => ['https'] // only allow https URLs
* ],
* 'sink' => '/path/to/file', // save to a file or a stream
* 'verify' => true, // bool or string to CA file
* 'debug' => true,
* 'timeout' => 5,
* @return IResponse
* @throws \Exception If the request could not get completed
*/
public function request(string $uri, string $method, array $options = []): IResponse {
$this->preventLocalAddress($uri, $options);
$response = $this->client->request($method, $uri, $this->buildRequestOptions($options));
$isStream = isset($options['stream']) && $options['stream'];
return new Response($response, $isStream);
}
protected function wrapGuzzlePromise(PromiseInterface $promise): IPromise {
return new GuzzlePromiseAdapter(
$promise,

@ -217,6 +217,37 @@ interface IClient {
*/
public function getResponseFromThrowable(\Throwable $e): IResponse;
/**
* Sends a HTTP request
* @param string $uri
* @param string $method The HTTP method to use
* @param array $options Array such as
* 'query' => [
* 'field' => 'abc',
* 'other_field' => '123',
* 'file_name' => fopen('/path/to/file', 'r'),
* ],
* 'headers' => [
* 'foo' => 'bar',
* ],
* 'cookies' => [
* 'foo' => 'bar',
* ],
* 'allow_redirects' => [
* 'max' => 10, // allow at most 10 redirects.
* 'strict' => true, // use "strict" RFC compliant redirects.
* 'referer' => true, // add a Referer header
* 'protocols' => ['https'] // only allow https URLs
* ],
* 'sink' => '/path/to/file', // save to a file or a stream
* 'verify' => true, // bool or string to CA file
* 'debug' => true,
* @return IResponse
* @throws \Exception If the request could not get completed
* @since 29.0.0
*/
public function request(string $uri, string $method, array $options = []): IResponse;
/**
* Sends an asynchronous GET request
* @param string $uri

Loading…
Cancel
Save