Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Commit 1327bee

Browse files
farktronixherrbischoff
authored andcommitted
Support etags (#7)
1 parent 0fc00f0 commit 1327bee

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

index.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,32 @@
8585
*/
8686
header('Content-type: application/rss+xml; charset=utf-8');
8787

88+
/**
89+
* Calculate the etag and compare
90+
*/
91+
$etag_hash = hash_init("sha256");
92+
if ($handle = opendir($media_base_path)) :
93+
while ($files[] = readdir($handle));
94+
sort($files);
95+
96+
foreach ($files as $entry) :
97+
$entry_path = $media_base_path . "/" . $entry;
98+
if (array_key_exists(pathinfo($entry_path, PATHINFO_EXTENSION), $exts) && !preg_match('/^\./', $entry)) :
99+
$mtime = (string)filemtime($entry_path);
100+
hash_update($etag_hash, $mtime);
101+
endif;
102+
endforeach;
103+
closedir($handle);
104+
endif;
105+
$etag = hash_final($etag_hash);
106+
107+
if (trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) :
108+
header("HTTP/1.1 304 Not Modified");
109+
exit;
110+
endif;
111+
112+
header("ETag: $etag");
113+
88114
/**
89115
* Get mediainfo path
90116
*/

0 commit comments

Comments
 (0)