forked from simplepie/simplepie
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'freshrss' into sync-upstream
- Loading branch information
Showing
15 changed files
with
468 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,6 @@ indent_style = space | |
[*.{yaml,yml}] | ||
indent_size = 2 | ||
indent_style = space | ||
|
||
[*.xml] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# SimplePie | ||
|
||
> SimplePie is a very fast and easy-to-use class, written in PHP, that puts the | ||
> *simple* back into *Really Simple Syndication* (RSS). Flexible enough to suit | ||
> beginners and veterans alike, SimplePie is focused on [speed, ease of use, | ||
> compatibility and standards compliance](http://simplepie.org/wiki/faq/what_is_simplepie). | ||
[Read the rest of the original readme](../README.markdown). | ||
|
||
## FreshRSS fork | ||
|
||
[This repository `FreshRSS/simplepie`](https://github.com/FreshRSS/simplepie) is a fork of the [main repository `simplepie/simplepie`](https://github.com/simplepie/simplepie) | ||
intended to be used for [FreshRSS](https://github.com/FreshRSS/FreshRSS), which is a free, self-hostable news aggregator. | ||
|
||
The default branch [`freshrss`](https://github.com/FreshRSS/simplepie/tree/freshrss) is the one used in [the FreshRSS codebase](https://github.com/FreshRSS/FreshRSS/tree/edge/lib/simplepie). | ||
|
||
This allows in particular to use fixes and patches, which have not (yet) been submitted upstream or not (yet) merged upstream. | ||
|
||
### Differences | ||
|
||
[See the differences](https://github.com/simplepie/simplepie/compare/master...FreshRSS:simplepie:freshrss). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ruleset name="SimplePie"> | ||
<arg name="extensions" value="php"/> | ||
<exclude-pattern>./.git/</exclude-pattern> | ||
<exclude-pattern>./compatibility_test/</exclude-pattern> | ||
<exclude-pattern>./vendor/</exclude-pattern> | ||
<rule ref="PSR12"> | ||
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols"/> | ||
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"/> | ||
<exclude name="PSR12.ControlStructures.ControlStructureSpacing.CloseParenthesisLine"/> | ||
<exclude name="PSR12.ControlStructures.ControlStructureSpacing.FirstExpressionLine"/> | ||
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace"/> | ||
</rule> | ||
<rule ref="Generic.Files.LineLength"> | ||
<properties> | ||
<property name="lineLimit" value="165"/> | ||
<property name="absoluteLineLimit" value="400"/> | ||
</properties> | ||
</rule> | ||
<rule ref="Generic.WhiteSpace.DisallowTabIndent.TabsUsed"> | ||
<exclude-pattern>./demo/</exclude-pattern> | ||
</rule> | ||
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace"> | ||
<exclude-pattern>./library/</exclude-pattern> | ||
</rule> | ||
<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps"> | ||
<exclude-pattern>./library/</exclude-pattern> | ||
</rule> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimplePie\HTTP; | ||
|
||
/** | ||
* HTTP util functions | ||
* FreshRSS | ||
* @internal | ||
*/ | ||
final class Utils | ||
{ | ||
/** | ||
* Extracts `max-age` from the `Cache-Control` HTTP headers | ||
* | ||
* @param array<string,mixed> $http_headers HTTP headers of the response | ||
* @return int|null The `max-age` value or `null` if not found | ||
* | ||
* FreshRSS | ||
*/ | ||
public static function get_http_max_age(array $http_headers): ?int | ||
{ | ||
$cache_control = $http_headers['cache-control'] ?? null; | ||
if (is_string($cache_control) && preg_match('/\bmax-age=(\d+)\b/', $cache_control, $matches)) { | ||
return (int) $matches[1]; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Negotiate the cache expiration time based on the HTTP response headers. | ||
* Return the cache duration time in number of seconds since the Unix Epoch, accounting for: | ||
* - `Cache-Control: max-age` minus `Age`, bounded by `$cache_duration_min` and `$cache_duration_max` | ||
* - `Cache-Control: must-revalidate` will set `$cache_duration` to `$cache_duration_min` | ||
* - `Cache-Control: no-cache` will return `time() + $cache_duration_min` | ||
* - `Cache-Control: no-store` will return `time() + $cache_duration_min - 3` | ||
* - `Expires` like `Cache-Control: max-age` but only if it is absent | ||
* | ||
* @param array<string,mixed> $http_headers HTTP headers of the response | ||
* @param int $cache_duration Desired cache duration in seconds, potentially overridden by HTTP response headers | ||
* @param int $cache_duration_min Minimal cache duration (in seconds), overriding HTTP response headers `Cache-Control` and `Expires`, | ||
* @param int $cache_duration_max Maximal cache duration (in seconds), overriding HTTP response headers `Cache-Control: max-age` and `Expires`, | ||
* @return int The negotiated cache expiration time in seconds since the Unix Epoch | ||
* | ||
* FreshRSS | ||
*/ | ||
public static function negociate_cache_expiration_time(array $http_headers, int $cache_duration, int $cache_duration_min, int $cache_duration_max): int | ||
{ | ||
$cache_control = $http_headers['cache-control'] ?? ''; | ||
if ($cache_control !== '') { | ||
if (preg_match('/\bno-store\b/', $cache_control)) { | ||
return time() + $cache_duration_min - 3; // -3 to distinguish from no-cache if needed | ||
} | ||
if (preg_match('/\bno-cache\b/', $cache_control)) { | ||
return time() + $cache_duration_min; | ||
} | ||
if (preg_match('/\bmust-revalidate\b/', $cache_control)) { | ||
$cache_duration = $cache_duration_min; | ||
} | ||
if (preg_match('/\bmax-age=(\d+)\b/', $cache_control, $matches)) { | ||
$max_age = (int) $matches[1]; | ||
$age = $http_headers['age'] ?? ''; | ||
if (is_numeric($age)) { | ||
$max_age -= (int) $age; | ||
} | ||
return time() + min(max($max_age, $cache_duration), $cache_duration_max); | ||
} | ||
} | ||
$expires = $http_headers['expires'] ?? ''; | ||
if ($expires !== '') { | ||
$expire_date = \SimplePie\Misc::parse_date($expires); | ||
if ($expire_date !== false) { | ||
return min(max($expire_date, time() + $cache_duration), time() + $cache_duration_max); | ||
} | ||
} | ||
return time() + $cache_duration; | ||
} | ||
} |
Oops, something went wrong.