diff options
author | Christian Schneider | 2024-04-24 22:55:40 +0200 |
---|---|---|
committer | Christian Schneider | 2024-04-24 22:55:40 +0200 |
commit | d4bd73f98063ebbdf6c6f5ce94252360de901c9a (patch) | |
tree | 6ec8162c5d9bff8f46005ab793667c4b5d1c19b3 | |
parent | 21e12e0b65c1a7a136c686523037991061cc35a2 (diff) | |
download | itools-d4bd73f98063ebbdf6c6f5ce94252360de901c9a.tar.gz itools-d4bd73f98063ebbdf6c6f5ce94252360de901c9a.tar.bz2 itools-d4bd73f98063ebbdf6c6f5ce94252360de901c9a.zip |
Switch it_url::get('assoc' => true) to always return non-empty array including at least the HTTP status code
-rw-r--r-- | it_url.class | 5 | ||||
-rwxr-xr-x | test/it_url.t | 2 |
2 files changed, 4 insertions, 3 deletions
diff --git a/it_url.class b/it_url.class index 637990c..91dfbf4 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,7 +615,8 @@ 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) + $response = $url->_get($p + ['checkonly' => true, 'filemtime' => EDC('nocache') ? null : $filemtime]); + if ($data = $p['assoc'] ? $response['data'] : $response) # $data === true means not modified (no new data fetched) { $success = true; $isnewfile = it_url::_atomicwrite($path, $p['assoc'] ? it::json_encode($data) : $data); diff --git a/test/it_url.t b/test/it_url.t index 568feda..47064b5 100755 --- a/test/it_url.t +++ b/test/it_url.t @@ -272,7 +272,7 @@ $output = handle_server( $output = handle_server( is( it::filter_keys(it_url::get(['url' => "http://$host/not_found_with_body", 'empty_on_fail' => true, 'it_error' => false, 'assoc' => true]), 'status,data'), - [], + ['status' => 404, 'data' => null], 'it_url::get() on 404 with body, empty_on_fail and assoc' ) ); |