mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-25 19:06:23 +03:00
[contents] Skip caching if the remote server requests no caching (#945)
* Skip caching if Cache-Control defines no-cache * Skip caching if Cache-Control defines no-store
This commit is contained in:
parent
263e8872ea
commit
3d301fc4ee
1 changed files with 14 additions and 0 deletions
|
@ -122,6 +122,20 @@ function getContents($url, $header = array(), $opts = array()){
|
|||
case 200: // Contents received
|
||||
Debug::log('New contents received');
|
||||
$data = substr($data, $headerSize);
|
||||
// Disable caching if the server responds with "Cache-Control: no-cache"
|
||||
// or "Cache-Control: no-store"
|
||||
$finalHeader = array_change_key_case($finalHeader, CASE_LOWER);
|
||||
if(array_key_exists('cache-control', $finalHeader)) {
|
||||
Debug::log('Server responded with "Cache-Control" header');
|
||||
$directives = explode(',', $finalHeader['cache-control']);
|
||||
$directives = array_map('trim', $directives);
|
||||
if(in_array('no-cache', $directives)
|
||||
|| in_array('no-store', $directives)) { // Skip caching
|
||||
Debug::log('Skip server side caching');
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Debug::log('Store response to cache');
|
||||
$cache->saveData($data);
|
||||
return $data;
|
||||
case 304: // Not modified, use cached data
|
||||
|
|
Loading…
Reference in a new issue