summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2024-07-03 18:30:40 +0200
committerUrban Müller2024-07-03 18:30:40 +0200
commit0f3b884db2baa72b87eb9c32ecdf03649598ae81 (patch)
tree92b47a27851ca1bb321db82ed05c95e2e194a7bd
parent5c567c34ccdbdcd667541bc0030c71ffb0152806 (diff)
downloaditools-0f3b884db2baa72b87eb9c32ecdf03649598ae81.tar.gz
itools-0f3b884db2baa72b87eb9c32ecdf03649598ae81.tar.bz2
itools-0f3b884db2baa72b87eb9c32ecdf03649598ae81.zip
make retries => 0 consistent with retries => 1: no it::error on 404
-rw-r--r--it_url.class14
-rwxr-xr-xtest/it_url.t10
2 files changed, 18 insertions, 6 deletions
diff --git a/it_url.class b/it_url.class
index a778aed..c2d7faf 100644
--- a/it_url.class
+++ b/it_url.class
@@ -41,7 +41,7 @@ class it_url
var $errstr; /* request error string */
var $curlinfo;
- static $retryable = "^(5..)$";
+ static $forceretry = "^(5..)$";
/**
* Constructor: canonicalize an URL
@@ -143,8 +143,7 @@ function _get($p = [])
$result = $this->request($p + ['followlocation' => true]);
$result = self::_postprocess($result, $p);
- # FIXME 2024-07 UM some failures never send errs in request() because retries > 0
- if ($p['retries'] > 0 && ((!$result && !it::match('^(204|4..)$', $this->result)) || it::match(self::$retryable, $this->result)))
+ if ($p['retries'] > 0 && self::retry_warranted($result, $this->result))
{
usleep($p['retrysleep']*1000000);
$result = $this->_get(array('retries' => $p['retries'] - 1) + $p);
@@ -163,6 +162,11 @@ function _get($p = [])
return $result;
}
+function retry_warranted($result, $status)
+{
+ return $result ? it::match(self::$forceretry, $status) : !it::match('^(204|4..)$', $status);
+}
+
function parse_http_header($header)
{
foreach (explode("\n", trim($header)) as $line)
@@ -377,7 +381,7 @@ function request($p=array())
fclose($stderr);
}
- if ($body === false && $p['retries'] <= 0)
+ if ($body === false && $p['retries'] <= 0 && self::retry_warranted($result, $this->result))
{
it::error((array)$p['it_error'] + [
'title' => "problem " . ($p['method'] ?: "gett") . "ing $url->url: " . $this->errstr,
@@ -482,7 +486,7 @@ static function get_multi($p=null)
if (!$p['noresults'])
$results_unordered[$key] = $content;
- if (it::match(self::$retryable, curl_getinfo($handles[$key], CURLINFO_RESPONSE_CODE)) && $retries[$key]++ < $p['retries'])
+ if (it::match(self::$forceretry, curl_getinfo($handles[$key], CURLINFO_RESPONSE_CODE)) && $retries[$key]++ < $p['retries'])
{
$sleepuntils[$key] = microtime(true) + $p['retrysleep'];
}
diff --git a/test/it_url.t b/test/it_url.t
index 2e7d4f2..71469a8 100755
--- a/test/it_url.t
+++ b/test/it_url.t
@@ -259,10 +259,18 @@ $output = handle_server(
);
if (!ok(
count(preg_grep('/^Got Request:/', $output)) == 1,
- 'it_url::get() does not retry on 404'
+ 'it_url::get() does not retry on 404, no it_error'
))
diag($output);
+
+handle_server(
+ ok(
+ !it_url::get(['url' => "http://$host/does_not_exist", 'retries' => 0]),
+ 'it_url::get() on 404, no it_error'
+ )
+);
+
$output = handle_server(
ok(
it_url::get(['url' => "http://$host/not_found_with_body", 'body_on_fail' => true, 'it_error' => false]),