diff options
author | Christian Schneider | 2024-04-29 09:36:51 +0200 |
---|---|---|
committer | Christian Schneider | 2024-04-29 09:36:51 +0200 |
commit | 4c0f5a738aaa5897cc36062d9555b2edbf5142f5 (patch) | |
tree | aedca21a80b07bcb2a4b4ad53429ac83ce310e00 /it_url.class | |
parent | b0a622196a793a36bdf77f79185acea85ba39730 (diff) | |
download | itools-4c0f5a738aaa5897cc36062d9555b2edbf5142f5.tar.gz itools-4c0f5a738aaa5897cc36062d9555b2edbf5142f5.tar.bz2 itools-4c0f5a738aaa5897cc36062d9555b2edbf5142f5.zip |
Version 2 of: Switch it_url::get('assoc' => true) to always return non-empty array including at least the HTTP status code
Diffstat (limited to 'it_url.class')
-rw-r--r-- | it_url.class | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/it_url.class b/it_url.class index 637990c..d9e4869 100644 --- a/it_url.class +++ b/it_url.class @@ -150,7 +150,7 @@ function _get($p = []) usleep($p['fetchsleep'] * 1000000); if ($p['assoc']) - $result = $result !== false ? [ 'status' => $this->result, 'data' => $this->data, 'headers' => $this->headers, 'cookies' => $this->cookies, 'errstr' => $this->errstr ] : []; + $result = [ 'status' => intval($this->result) ?: 503, 'data' => $result !== false ? $this->data : null, 'headers' => $this->headers, 'cookies' => $this->cookies, 'errstr' => $this->errstr ]; EDC('curlinfo', $this->result, $this->headers, $this->cookies, $this->errstr); @@ -615,10 +615,11 @@ static function get_cache($p = array()) EDC('getcache', "new", $filemtime, $p['url'], $path); $url = new it_url; - if ($data = $url->_get($p + ['checkonly' => true, 'filemtime' => EDC('nocache') ? null : $filemtime])) # => true means not modified (no new data fetched) + $data = $url->_get($p + ['checkonly' => true, 'filemtime' => EDC('nocache') ? null : $filemtime]); + if ($p['assoc'] ? ($data['status'] == 304 || $data['data']) : $data) { $success = true; - $isnewfile = it_url::_atomicwrite($path, $p['assoc'] ? it::json_encode($data) : $data); + $isnewfile = it_url::_atomicwrite($path, $p['assoc'] ? ($data['status'] === 304 ? true : it::json_encode($data)) : $data); # $data === true means not modified (no new data fetched) and instructs _atomicwrite to just touch the file if ($p['returnheaders']) it::file_put("$path.json", it::json_encode($url->headers)); } |