summaryrefslogtreecommitdiff
path: root/it_url.class
diff options
context:
space:
mode:
authorChristian Helbling2017-07-03 14:53:34 +0200
committerChristian Helbling2017-07-03 14:53:34 +0200
commit4d3956ddba5aeb99655abfca0b1eba020afbefdd (patch)
treee98ab3346ae7c37708fef7557b106682a7ffcd0d /it_url.class
parentf4b9ee7bd58b146996d25b1663d7e64b22b97847 (diff)
downloaditools-4d3956ddba5aeb99655abfca0b1eba020afbefdd.tar.gz
itools-4d3956ddba5aeb99655abfca0b1eba020afbefdd.tar.bz2
itools-4d3956ddba5aeb99655abfca0b1eba020afbefdd.zip
add filemtime / If-Modified-Since functionality to request_curl
Diffstat (limited to 'it_url.class')
-rw-r--r--it_url.class15
1 files changed, 8 insertions, 7 deletions
diff --git a/it_url.class b/it_url.class
index 3525117..c32eb91 100644
--- a/it_url.class
+++ b/it_url.class
@@ -166,13 +166,16 @@ function parse_http_header($header)
static function _default_headers($url, $p)
{
- return [
+ $headers = [
'Host' => $url->realhostname . $url->explicitport,
'User-Agent' => "Mozilla/5.0 (compatible; MSIE 9.0; ITools)",
'Accept-Language' => $p['headers']['Accept-Language'] ?: T_lang(), # can prevent loading of it_text
'Referer' => it::match('([-\w]+\.\w+)$', $url->hostname) == it::match('([-\w]+\.\w+)$', $_SERVER['HTTP_HOST']) ? it_url::absolute(U($_GET)) : null,
'X-Ultra-Https' => $_SERVER['HTTPS'],
];
+ if (is_int($p['filemtime']))
+ $headers['If-Modified-Since'] = date("r", $p['filemtime']);
+ return $headers;
}
function request($p=array())
@@ -196,9 +199,6 @@ function request($p=array())
$p['headers'] = (array)$p['headers'] + self::_default_headers($url, $p);
- if (is_int($p['filemtime']))
- $p['headers']['If-Modified-Since'] = date("r", $p['filemtime']);
-
if ($datalen = strlen($data))
{
$method = $p['method'] ?: "POST";
@@ -324,8 +324,6 @@ static function curl_opts($p=array())
/*
* drop in replacement for request using curl
*
- * todo:
- * @param $p['filemtime'] Add HTTP header to only fetch when newer than this, otherwise return true instead of data
* @param $p['data'] POST data array with key-value pairs
* @param $p['files'] [fieldname => filename] of files to upload
* @param $p['method'] different HTTP method
@@ -359,8 +357,11 @@ function request_curl($p=array())
if ($p['maxlength'] && (strlen($this->data) > $p['maxlength'])) {
$result = $this->result = false;
$errstr = $this->errstr = "maxlength reached";
- } else
+ } else if ($p['filemtime'] && ($url->result == 304)) {
+ $result = true; # Not modified, success but no data
+ } else {
$result =& $url->data;
+ }
} else {
$result = $this->result = false;
$errstr = $this->errstr = curl_error($curl);