diff options
Diffstat (limited to 'lib/Config')
-rw-r--r-- | lib/Config/FetcherConfig.php | 72 |
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; } /** |