# HG changeset patch # User Dan # Date 1233212627 18000 # Node ID 689b095d02cf387efc3e73a615fcbd1f94204000 # Parent 205d0534a0f2439b4da6be600dcb93251d9a224b Added Not-Modified support to fetcher; made caching more aggressive diff -r 205d0534a0f2 -r 689b095d02cf plugins/gallery/fetcher.php --- a/plugins/gallery/fetcher.php Thu Jan 29 01:30:09 2009 -0500 +++ b/plugins/gallery/fetcher.php Thu Jan 29 02:03:47 2009 -0500 @@ -136,10 +136,25 @@ die('Can\'t retrieve image file ' . $filename); $contents = file_get_contents($filename); + // expire images 30 days from now + $expiry = time() + ( 30 * 86400 ); header('Content-type: ' . $mimetype); header('Content-length: ' . strlen($contents)); header('Last-Modified: ' . date('r', $row['img_time_mod'])); + header('Expires: ' . date('r', $expiry)); + + // check for not-modified condition + if ( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ) + { + $time = @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']); + if ( ( !empty($time) && intval($row['img_time_mod']) <= $time ) || date('r', $row['img_time_mod']) === $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) + { + header('HTTP/1.1 304 Not Modified'); + $db->close(); + exit; + } + } if ( isset($_GET['download']) ) {