From ced5bfa06c5003ca03d17838c59e7bc4290c2d4d Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Fri, 9 Dec 2011 16:45:14 +0000 Subject: Added parameter $p["returnheaders"] => true to return array($path, $headers) for url instead of only $path --- it_url.class | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/it_url.class b/it_url.class index da6f033..cf7f45a 100644 --- a/it_url.class +++ b/it_url.class @@ -459,6 +459,7 @@ function get_cache_filename($p) * @param $p['preprocess'] callback function (or array for methods) to change received file or array('function' => ..., 'in' => $src, 'out' => $dst, ...) with callback function plus args * @param $p['safety'] value 0 means dont generate alert, value 1 means generate alerts on timeouts and failures * @param $p['keepfailed'] keep old versions of files if download fails (sending alerts conservatively) + * @param $p['returnheaders'] Return array($path, $headers) instead of simply $path * @param $p['it_error'] parameters for it::error() */ function get_cache($p = array()) @@ -485,8 +486,13 @@ function get_cache($p = array()) touch($path); EDC('getcache', "new", $filemtime, $p['url'], $path); - if ($result = it_url::get($p + array('filemtime' => EDC('nocache') ? null : $filemtime))) # => true means not modified (no new data fetched) + $url = new it_url; + if ($result = $url->get($p + array('filemtime' => EDC('nocache') ? null : $filemtime))) # => true means not modified (no new data fetched) + { $newfile = it_url::_atomicwrite($path, $result); + if ($p['returnheaders']) + file_put_contents("$path.headers", 'headers, true) . ";\n"); + } else if ($p['keepfailed']) $result = $fileexists; else @@ -513,6 +519,10 @@ function get_cache($p = array()) $result = true; # Up to date } + # Read headers before $path is modified for preprocessing + if ($p['returnheaders']) + $headers = @include("$path.headers"); + if ($result && $p['preprocess']) { $srcpath = $path; @@ -565,7 +575,7 @@ function get_cache($p = array()) } EDC('getcache', $result, $path); - return $result ? $path : false; + return $result ? ($p['returnheaders'] ? array($path, $headers) : $path) : false; } /** -- cgit v1.2.3