summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2024-05-08 13:37:08 +0200
committerChristian Schneider2024-05-08 13:37:08 +0200
commitd4515d6d78e3902c557b8957e74e250424d7932b (patch)
tree3575fb392d640e65018c5489e21f5ca8b4138cd1
parent140dc151919101c38f16d0a7dc4221941651f74d (diff)
downloaditools-d4515d6d78e3902c557b8957e74e250424d7932b.tar.gz
itools-d4515d6d78e3902c557b8957e74e250424d7932b.tar.bz2
itools-d4515d6d78e3902c557b8957e74e250424d7932b.zip
Switch default for it_url::get*() to not return body on status >= 400
-rw-r--r--it_url.class8
-rwxr-xr-xtest/it_url.t8
2 files changed, 10 insertions, 6 deletions
diff --git a/it_url.class b/it_url.class
index b38eaf1..a0ba77f 100644
--- a/it_url.class
+++ b/it_url.class
@@ -108,7 +108,7 @@ static function _postprocess($data, $p)
* @param $p['safety'] DEPRECATED. 0 = ignore errors, 1 = errors, 2 = fatals
* @param $p['it_error'] extra arguments for it_error or false to ignore errors
* @param $p['fetchsleep'] Number of seconds to wait after fetch, fractions ok
- * @param $p['body_on_fail'] Return body of page even if http status code is >= 400
+ * @param $p['body_on_fail'] Return body of page even if http status code is >= 400, e.g. some JSON APIs return 404 with JSON data
*
* Result processing
* @param $p['assoc'] Return [ 'data' => string, 'status' => int, 'cookies' => array, 'headers' => array, 'errstr' => string ] instead of just data
@@ -360,11 +360,7 @@ function request($p=array())
}
else
{
- # FIXME 2024-06 CS Send a notice in cases where changing the default to body_on_fail=false would change result for text results
- if ($url->result >= 400 && $url->data && !$p['assoc'] && !isset($p['body_on_fail']) && it::match('^text/', $url->headers['Content-Type']))
- it::error(['to' => 'schneider@search.ch', 'title' => 'Failing it_url::get() without body_on_fail but non-empty data', 'body' => ['p' => $p, 'url' => $url]]);
-
- if ($url->result >= 400 && ((isset($p['body_on_fail']) && !$p['body_on_fail']) || $p['empty_on_fail'] || $p['keepfailed'])) # FIXME 2024-06 CS Remove deprecated empty_on_fail support
+ if ($url->result >= 400 && (!$p['body_on_fail'] || $p['keepfailed']))
$got = $url->data = false;
$result =& $url->data;
$this->errstr = "HTTP Status " . $url->result;
diff --git a/test/it_url.t b/test/it_url.t
index 5f2d1d0..2e7d4f2 100755
--- a/test/it_url.t
+++ b/test/it_url.t
@@ -280,6 +280,14 @@ $output = handle_server(
$output = handle_server(
is(
+ it_url::get(['url' => "http://$host/not_found_with_body", 'it_error' => false]),
+ false,
+ 'it_url::get() on 404 with body and default for body_on_fail'
+ )
+);
+
+$output = handle_server(
+ is(
it::filter_keys(it_url::get(['url' => "http://$host/not_found_with_body", 'body_on_fail' => false, 'it_error' => false, 'assoc' => true]), 'status,data'),
['status' => 404, 'data' => null],
'it_url::get() on 404 with body, body_on_fail and assoc'