summaryrefslogtreecommitdiffstats
path: root/lib/Config
diff options
context:
space:
mode:
authorSean Molenaar <SMillerDev@users.noreply.github.com>2019-03-17 08:23:37 +0100
committerBenjamin Brahmer <info@b-brahmer.de>2019-03-17 08:23:37 +0100
commit2698214c4122d4f5f63f26f7a204035fe0d4f211 (patch)
treee1a033654736cc68f698af7110e8e17fdb0c2e55 /lib/Config
parentf5e25d2edef3360ed7fcdc1ecc663cfb37b650b7 (diff)
fix/allow CDATA encoding (#428)
Diffstat (limited to 'lib/Config')
-rw-r--r--lib/Config/FetcherConfig.php68
1 files changed, 35 insertions, 33 deletions
diff --git a/lib/Config/FetcherConfig.php b/lib/Config/FetcherConfig.php
index 55603c47c..1459ff032 100644
--- a/lib/Config/FetcherConfig.php
+++ b/lib/Config/FetcherConfig.php
@@ -16,6 +16,7 @@ namespace OCA\News\Config;
use FeedIo\Adapter\ClientInterface;
use \GuzzleHttp\Client;
use \FeedIo\Adapter\Guzzle\Client as FeedIoClient;
+use OCP\IConfig;
/**
* Class FetcherConfig
@@ -26,6 +27,8 @@ class FetcherConfig
{
protected $client_timeout;
protected $proxy;
+ protected $redirects;
+ protected $max_size;
/**
* Configure a guzzle client
@@ -36,14 +39,18 @@ class FetcherConfig
{
if (!class_exists('GuzzleHttp\Collection')) {
$config = [
- 'timeout' => $this->getClientTimeout(),
+ 'timeout' => $this->client_timeout,
];
if (!empty($this->proxy)) {
$config['proxy'] = $this->proxy;
}
- $guzzle = new Client();
+ if (!empty($this->redirects)) {
+ $config['redirect.max'] = $this->redirects;
+ }
+
+ $guzzle = new Client($config);
$client = new FeedIoClient($guzzle);
return $client;
@@ -51,7 +58,7 @@ class FetcherConfig
$config = [
'request.options' => [
- 'timeout' => $this->getClientTimeout(),
+ 'timeout' => $this->client_timeout,
],
];
@@ -59,59 +66,54 @@ class FetcherConfig
$config['request.options']['proxy'] = $this->proxy;
}
+ if (!empty($this->redirects)) {
+ $config['request.options']['redirect.max'] = $this->redirects;
+ }
+
$guzzle = new Client($config);
return new LegacyGuzzleClient($guzzle);
}
/**
- * Set a timeout for the client
+ * Set settings for config.
*
- * @param int $timeout The timeout
+ * @param Config $config The shared configuration
*
* @return self
*/
- public function setClientTimeout($timeout)
+ public function setConfig(Config $config)
{
- $this->client_timeout = $timeout;
+ $this->client_timeout = $config->getFeedFetcherTimeout();
+ $this->redirects = $config->getMaxRedirects();
+ $this->max_size = $config->getMaxSize();
return $this;
}
/**
- * Get the client timeout.
- *
- * @return mixed
- */
- public function getClientTimeout()
- {
- return $this->client_timeout;
- }
-
- /**
* Set the proxy
*
- * @param \OCA\News\Utility\ProxyConfigParser $proxy The proxy to set.
+ * @param IConfig $config Nextcloud config.
*
* @return self
*/
- public function setProxy($proxy)
+ public function setProxy(IConfig $config)
{
- // proxy settings
- $proxySettings = $proxy->parse();
- $host = $proxySettings['host'];
- $port = $proxySettings['port'];
- $user = $proxySettings['user'];
- $password = $proxySettings['password'];
-
- $proxy_string = 'https://';
- if (!empty($user)) {
- $proxy_string .= $user . ':' . $password . '@';
+ $proxy = $config->getSystemValue('proxy', null);
+ $creds = $config->getSystemValue('proxyuserpwd', null);
+
+ if (is_null($proxy)) {
+ return $this;
}
- $proxy_string .= $host;
- if (!empty($port)) {
- $proxy_string .= ':' . $port;
+
+ $url = new \Net_URL2($proxy);
+
+ if ($creds) {
+ $auth = explode(':', $creds, 2);
+ $url->setUserinfo($auth[0], $auth[1]);
}
- $this->proxy = $proxy_string;
+
+ $this->proxy = $url->getNormalizedURL();
return $this;
}