Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the
### Fixed
- global starred count not updated when deleting a feed with starred items
- feed fetcher requests may get stuck
- feed logo download and `fulltext` scraper don't use configured proxy

# Releases
## [28.0.0-beta.2] - 2026-01-12
Expand Down
40 changes: 33 additions & 7 deletions lib/Config/FetcherConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class FetcherConfig
*/
public const SLEEPY_DURATION = 7 * 86400;

/**
* Connect timeout for the guzzle http client
* @var int
*/
public const CONNECT_TIMEOUT = 3;

/**
* Logger
* @var LoggerInterface
Expand Down Expand Up @@ -181,21 +187,42 @@ public function checkEncoding(): string
}

/**
* Configure a guzzle client
* Configure a feedio client
*
* @return ClientInterface Client to guzzle.
* @return ClientInterface Client to feedio client.
*/
public function getClient(): ClientInterface
{
$config = [
'connect_timeout' => 3,
'timeout' => $this->client_timeout,
'headers' => [
'User-Agent' => $this->getUserAgent(),
'Accept' => static::DEFAULT_ACCEPT,
'Accept-Encoding' => $this->checkEncoding()
],
];
$client = $this->getHttpClient($config);
return new FeedIoClient($client);
}

/**
* Configure a guzzle client
*
* @param array $config
* @return \GuzzleHttp\Client configured Guzzle HTTP client
*/
public function getHttpClient(array $config): \GuzzleHttp\Client
{
if (!isset($config['headers']) || !is_array($config['headers'])) {
$config['headers'] = [];
}
$config['headers']['User-Agent'] = $this->getUserAgent();

if (!isset($config['timeout'])) {
$config['timeout'] = $this->client_timeout;
}

if (!isset($config['connect_timeout'])) {
$config['connect_timeout'] = static::CONNECT_TIMEOUT;
}

if (!is_null($this->proxy)) {
$config['proxy'] = $this->proxy;
Expand All @@ -204,8 +231,7 @@ public function getClient(): ClientInterface
$config['redirect.max'] = $this->redirects;
}

$client = new Client($config);
return new FeedIoClient($client);
return new Client($config);
}

/**
Expand Down
24 changes: 11 additions & 13 deletions lib/Fetcher/FeedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use OCA\News\Vendor\FeedIo\FeedInterface;
use OCA\News\Vendor\FeedIo\FeedIo;
use OCA\News\Vendor\FeedIo\Reader\ReadErrorException;
use GuzzleHttp\Client;
use OCA\News\Vendor\GuzzleHttp\Psr7\Uri;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ConnectException;
Expand Down Expand Up @@ -130,12 +129,12 @@ public function canHandle(string $url): bool
public function hasLastModifiedHeader(string $url): bool
{
$hasLastModified = false;
$httpClientConfig = [
'base_uri' => $url,
'timeout' => 3,
];
try {
$client = new Client([
'base_uri' => $url,
'connect_timeout' => 3,
'timeout' => 3,
]);
$client = $this->fetcherConfig->getHttpClient($httpClientConfig);
$response = $client->request('HEAD');
$hasLastModified = $response->hasHeader('Last-Modified');
} catch (\Exception) {
Expand Down Expand Up @@ -560,20 +559,19 @@ protected function downloadFavicon(
$last_modified = 0;
}

// Base_uri can only be set on creation, will be used when link is relative.
$httpClientConfig = [
'base_uri' => $base_url,
'timeout' => 10,
];
try {
// Base_uri can only be set on creation, will be used when link is relative.
$client = new Client([
'base_uri' => $base_url,
'connect_timeout' => 3,
'timeout' => 10,
]);
$client = $this->fetcherConfig->getHttpClient($httpClientConfig);
$response = $client->request(
'GET',
$favicon_url,
[
'sink' => $favicon_cache,
'headers' => [
'User-Agent' => FetcherConfig::DEFAULT_USER_AGENT,
'Accept' => 'image/*',
'If-Modified-Since' => date(DateTime::RFC7231, $last_modified),
'Accept-Encoding' => $this->fetcherConfig->checkEncoding()
Expand Down
5 changes: 5 additions & 0 deletions lib/Scraper/Scraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public function __construct(LoggerInterface $logger, FetcherConfig $fetcherConfi
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);

$proxy = $this->fetcherConfig->getProxy();
if (!is_null($proxy) && $proxy !== '') {
$this->curl_opts[CURLOPT_PROXY] = $proxy;
}
}

private function getHTTPContent(string $url): array
Expand Down
Loading