summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2019-03-14 14:14:57 +0100
committerSean Molenaar <SMillerDev@users.noreply.github.com>2019-03-18 10:39:32 +0100
commit6ed63bdedd859f6eb4e5ea4a992867a295a200fd (patch)
tree0494776a9e0a09a67c3f8a0ddb00920a0893fe99 /lib
parent2698214c4122d4f5f63f26f7a204035fe0d4f211 (diff)
Set nextcloud user agent
Diffstat (limited to 'lib')
-rw-r--r--lib/Config/FetcherConfig.php72
1 files changed, 57 insertions, 15 deletions
diff --git a/lib/Config/FetcherConfig.php b/lib/Config/FetcherConfig.php
index 1459ff032..3110b0018 100644
--- a/lib/Config/FetcherConfig.php
+++ b/lib/Config/FetcherConfig.php
@@ -25,12 +25,38 @@ use OCP\IConfig;
*/
class FetcherConfig
{
+ /**
+ * Timeout before the client should abort.
+ * @var string
+ */
protected $client_timeout;
+
+ /**
+ * Configuration for an HTTP proxy.
+ * @var string
+ */
protected $proxy;
+
+ /**
+ * Amount of allowed redirects.
+ * @var string
+ */
protected $redirects;
+
+ /**
+ * Max size of the recieved data.
+ * @deprecated guzzle can't handle this
+ * @var string
+ */
protected $max_size;
/**
+ * User agent for the client.
+ * @var string
+ */
+ const DEFAULT_USER_AGENT = 'NextCloud-News/1.0';
+
+ /**
* Configure a guzzle client
*
* @return ClientInterface Legacy client to guzzle.
@@ -38,27 +64,43 @@ class FetcherConfig
public function getClient()
{
if (!class_exists('GuzzleHttp\Collection')) {
- $config = [
- 'timeout' => $this->client_timeout,
- ];
-
- if (!empty($this->proxy)) {
- $config['proxy'] = $this->proxy;
- }
-
- if (!empty($this->redirects)) {
- $config['redirect.max'] = $this->redirects;
- }
+ return new FeedIoClient($this->getConfig());
+ }
- $guzzle = new Client($config);
- $client = new FeedIoClient($guzzle);
+ return new LegacyGuzzleClient($this->getOldConfig());
+ }
+ /**
+ * Get configuration for modern guzzle.
+ * @return Client Guzzle client.
+ */
+ private function getConfig()
+ {
+ $config = [
+ 'timeout' => $this->client_timeout,
+ 'headers' => ['User-Agent' => static::DEFAULT_USER_AGENT],
+ ];
- return $client;
+ if (!empty($this->proxy)) {
+ $config['proxy'] = $this->proxy;
}
+ if (!empty($this->redirects)) {
+ $config['redirect.max'] = $this->redirects;
+ }
+
+ $guzzle = new Client($config);
+ return $guzzle;
+ }
+ /**
+ * Get configuration for old guzzle.
+ * @return Client Guzzle client.
+ */
+ private function getOldConfig()
+ {
$config = [
'request.options' => [
'timeout' => $this->client_timeout,
+ 'headers' => ['User-Agent' => static::DEFAULT_USER_AGENT],
],
];
@@ -71,7 +113,7 @@ class FetcherConfig
}
$guzzle = new Client($config);
- return new LegacyGuzzleClient($guzzle);
+ return $guzzle;
}
/**