aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Http/Client
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Http/Client')
-rw-r--r--lib/private/Http/Client/Client.php399
-rw-r--r--lib/private/Http/Client/ClientService.php3
-rw-r--r--lib/private/Http/Client/GuzzlePromiseAdapter.php44
-rw-r--r--lib/private/Http/Client/Response.php13
4 files changed, 0 insertions, 459 deletions
diff --git a/lib/private/Http/Client/Client.php b/lib/private/Http/Client/Client.php
index 0b72522c218..68b101cc41a 100644
--- a/lib/private/Http/Client/Client.php
+++ b/lib/private/Http/Client/Client.php
@@ -171,35 +171,6 @@ class Client implements IClient {
}
}
- /**
- * Sends a GET request
- *
- * @param string $uri
- * @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 get(string $uri, array $options = []): IResponse {
$this->preventLocalAddress($uri, $options);
$response = $this->client->request('get', $uri, $this->buildRequestOptions($options));
@@ -207,65 +178,12 @@ class Client implements IClient {
return new Response($response, $isStream);
}
- /**
- * Sends a HEAD request
- *
- * @param string $uri
- * @param array $options Array such as
- * '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 head(string $uri, array $options = []): IResponse {
$this->preventLocalAddress($uri, $options);
$response = $this->client->request('head', $uri, $this->buildRequestOptions($options));
return new Response($response);
}
- /**
- * Sends a POST request
- *
- * @param string $uri
- * @param array $options Array such as
- * 'body' => [
- * '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 post(string $uri, array $options = []): IResponse {
$this->preventLocalAddress($uri, $options);
@@ -278,154 +196,30 @@ class Client implements IClient {
return new Response($response, $isStream);
}
- /**
- * Sends a PUT request
- *
- * @param string $uri
- * @param array $options Array such as
- * 'body' => [
- * '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 put(string $uri, array $options = []): IResponse {
$this->preventLocalAddress($uri, $options);
$response = $this->client->request('put', $uri, $this->buildRequestOptions($options));
return new Response($response);
}
- /**
- * Sends a PATCH request
- *
- * @param string $uri
- * @param array $options Array such as
- * 'body' => [
- * '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 patch(string $uri, array $options = []): IResponse {
$this->preventLocalAddress($uri, $options);
$response = $this->client->request('patch', $uri, $this->buildRequestOptions($options));
return new Response($response);
}
- /**
- * Sends a DELETE request
- *
- * @param string $uri
- * @param array $options Array such as
- * 'body' => [
- * '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 delete(string $uri, array $options = []): IResponse {
$this->preventLocalAddress($uri, $options);
$response = $this->client->request('delete', $uri, $this->buildRequestOptions($options));
return new Response($response);
}
- /**
- * Sends an OPTIONS request
- *
- * @param string $uri
- * @param array $options Array such as
- * 'body' => [
- * '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 options(string $uri, array $options = []): IResponse {
$this->preventLocalAddress($uri, $options);
$response = $this->client->request('options', $uri, $this->buildRequestOptions($options));
return new Response($response);
}
- /**
- * Get the response of a Throwable thrown by the request methods when possible
- *
- * @param \Throwable $e
- * @return IResponse
- * @throws \Throwable When $e did not have a response
- * @since 29.0.0
- */
public function getResponseFromThrowable(\Throwable $e): IResponse {
if (method_exists($e, 'hasResponse') && method_exists($e, 'getResponse') && $e->hasResponse()) {
return new Response($e->getResponse());
@@ -434,36 +228,6 @@ class Client implements IClient {
throw $e;
}
- /**
- * Sends a HTTP request
- *
- * @param string $method The HTTP method to use
- * @param string $uri
- * @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 $method, string $uri, array $options = []): IResponse {
$this->preventLocalAddress($uri, $options);
$response = $this->client->request($method, $uri, $this->buildRequestOptions($options));
@@ -478,97 +242,18 @@ class Client implements IClient {
);
}
- /**
- * Sends an asynchronous GET request
- *
- * @param string $uri
- * @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 IPromise
- */
public function getAsync(string $uri, array $options = []): IPromise {
$this->preventLocalAddress($uri, $options);
$response = $this->client->requestAsync('get', $uri, $this->buildRequestOptions($options));
return $this->wrapGuzzlePromise($response);
}
- /**
- * Sends an asynchronous HEAD request
- *
- * @param string $uri
- * @param array $options Array such as
- * '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 IPromise
- */
public function headAsync(string $uri, array $options = []): IPromise {
$this->preventLocalAddress($uri, $options);
$response = $this->client->requestAsync('head', $uri, $this->buildRequestOptions($options));
return $this->wrapGuzzlePromise($response);
}
- /**
- * Sends an asynchronous POST request
- *
- * @param string $uri
- * @param array $options Array such as
- * 'body' => [
- * '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 IPromise
- */
public function postAsync(string $uri, array $options = []): IPromise {
$this->preventLocalAddress($uri, $options);
@@ -580,102 +265,18 @@ class Client implements IClient {
return $this->wrapGuzzlePromise($this->client->requestAsync('post', $uri, $this->buildRequestOptions($options)));
}
- /**
- * Sends an asynchronous PUT request
- *
- * @param string $uri
- * @param array $options Array such as
- * 'body' => [
- * '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 IPromise
- */
public function putAsync(string $uri, array $options = []): IPromise {
$this->preventLocalAddress($uri, $options);
$response = $this->client->requestAsync('put', $uri, $this->buildRequestOptions($options));
return $this->wrapGuzzlePromise($response);
}
- /**
- * Sends an asynchronous DELETE request
- *
- * @param string $uri
- * @param array $options Array such as
- * 'body' => [
- * '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 IPromise
- */
public function deleteAsync(string $uri, array $options = []): IPromise {
$this->preventLocalAddress($uri, $options);
$response = $this->client->requestAsync('delete', $uri, $this->buildRequestOptions($options));
return $this->wrapGuzzlePromise($response);
}
- /**
- * Sends an asynchronous OPTIONS request
- *
- * @param string $uri
- * @param array $options Array such as
- * 'body' => [
- * '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 IPromise
- */
public function optionsAsync(string $uri, array $options = []): IPromise {
$this->preventLocalAddress($uri, $options);
$response = $this->client->requestAsync('options', $uri, $this->buildRequestOptions($options));
diff --git a/lib/private/Http/Client/ClientService.php b/lib/private/Http/Client/ClientService.php
index b719f3d369d..e30749949ad 100644
--- a/lib/private/Http/Client/ClientService.php
+++ b/lib/private/Http/Client/ClientService.php
@@ -51,9 +51,6 @@ class ClientService implements IClientService {
$this->eventLogger = $eventLogger;
}
- /**
- * @return Client
- */
public function newClient(): IClient {
$handler = new CurlHandler();
$stack = HandlerStack::create($handler);
diff --git a/lib/private/Http/Client/GuzzlePromiseAdapter.php b/lib/private/Http/Client/GuzzlePromiseAdapter.php
index 03a9ed9a599..b147a93c09e 100644
--- a/lib/private/Http/Client/GuzzlePromiseAdapter.php
+++ b/lib/private/Http/Client/GuzzlePromiseAdapter.php
@@ -9,12 +9,9 @@ declare(strict_types=1);
namespace OC\Http\Client;
-use Exception;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Promise\PromiseInterface;
-use LogicException;
use OCP\Http\Client\IPromise;
-use OCP\Http\Client\IResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
@@ -31,16 +28,6 @@ class GuzzlePromiseAdapter implements IPromise {
) {
}
- /**
- * Appends fulfillment and rejection handlers to the promise, and returns
- * a new promise resolving to the return value of the called handler.
- *
- * @param ?callable(IResponse): void $onFulfilled Invoked when the promise fulfills. Gets an \OCP\Http\Client\IResponse passed in as argument
- * @param ?callable(Exception): void $onRejected Invoked when the promise is rejected. Gets an \Exception passed in as argument
- *
- * @return IPromise
- * @since 28.0.0
- */
public function then(
?callable $onFulfilled = null,
?callable $onRejected = null,
@@ -65,15 +52,6 @@ class GuzzlePromiseAdapter implements IPromise {
return $this;
}
- /**
- * Get the state of the promise ("pending", "rejected", or "fulfilled").
- *
- * The three states can be checked against the constants defined:
- * STATE_PENDING, STATE_FULFILLED, and STATE_REJECTED.
- *
- * @return IPromise::STATE_*
- * @since 28.0.0
- */
public function getState(): string {
$state = $this->promise->getState();
if ($state === PromiseInterface::FULFILLED) {
@@ -92,32 +70,10 @@ class GuzzlePromiseAdapter implements IPromise {
return self::STATE_PENDING;
}
- /**
- * Cancels the promise if possible.
- *
- * @link https://github.com/promises-aplus/cancellation-spec/issues/7
- * @since 28.0.0
- */
public function cancel(): void {
$this->promise->cancel();
}
- /**
- * Waits until the promise completes if possible.
- *
- * Pass $unwrap as true to unwrap the result of the promise, either
- * returning the resolved value or throwing the rejected exception.
- *
- * If the promise cannot be waited on, then the promise will be rejected.
- *
- * @param bool $unwrap
- *
- * @return mixed
- *
- * @throws LogicException if the promise has no wait function or if the
- * promise does not settle after waiting.
- * @since 28.0.0
- */
public function wait(bool $unwrap = true): mixed {
return $this->promise->wait($unwrap);
}
diff --git a/lib/private/Http/Client/Response.php b/lib/private/Http/Client/Response.php
index adf83306d07..09b668b61ee 100644
--- a/lib/private/Http/Client/Response.php
+++ b/lib/private/Http/Client/Response.php
@@ -34,26 +34,16 @@ class Response implements IResponse {
$this->stream = $stream;
}
- /**
- * @return string|resource
- */
public function getBody() {
return $this->stream ?
$this->response->getBody()->detach():
$this->response->getBody()->getContents();
}
- /**
- * @return int
- */
public function getStatusCode(): int {
return $this->response->getStatusCode();
}
- /**
- * @param string $key
- * @return string
- */
public function getHeader(string $key): string {
$headers = $this->response->getHeader($key);
@@ -64,9 +54,6 @@ class Response implements IResponse {
return $headers[0];
}
- /**
- * @return array
- */
public function getHeaders(): array {
return $this->response->getHeaders();
}