diff options
author | Christian Schneider | 2024-05-02 16:58:27 +0200 |
---|---|---|
committer | Christian Schneider | 2024-05-02 16:58:27 +0200 |
commit | b1b06fc503373630d49bcc9adff916ae94e2552a (patch) | |
tree | 46bbdfd11f426a3b11fc9412cc44cec2ff620924 | |
parent | b8af96c80cebdd9fae0f7200937615b4958d9f2a (diff) | |
download | itools-b1b06fc503373630d49bcc9adff916ae94e2552a.tar.gz itools-b1b06fc503373630d49bcc9adff916ae94e2552a.tar.bz2 itools-b1b06fc503373630d49bcc9adff916ae94e2552a.zip |
Rename empty_on_fail to body_on_fail for future switching of default, currently also supports empty_on_fail for transition
-rw-r--r-- | it_url.class | 10 | ||||
-rwxr-xr-x | test/it_url.t | 14 |
2 files changed, 12 insertions, 12 deletions
diff --git a/it_url.class b/it_url.class index 091baf9..53705c4 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['empty_on_fail'] Return empty page if http status code is >= 400 + * @param $p['body_on_fail'] Return body of page even if http status code is >= 400 * * Result processing * @param $p['assoc'] Return [ 'data' => string, 'status' => int, 'cookies' => array, 'headers' => array, 'errstr' => string ] instead of just data @@ -360,11 +360,11 @@ function request($p=array()) } else { - # FIXME 2024-06 CS Send a notice in cases where changing the default to empty_on_fail=true would change result for text results - #if ($url->result >= 400 && $url->data && !isset($p['empty_on_fail']) && it::match('^text/', $url->headers['Content-Type'])) - # it::error(['to' => 'schneider@search.ch', 'title' => 'Failing it_url::get() without empty_on_fail but non-empty data', 'body' => ['p' => $p, 'url' => $url]]); + # 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 && !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 && ($p['empty_on_fail'] || $p['keepfailed'])) + 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 $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 1898d4b..302a754 100755 --- a/test/it_url.t +++ b/test/it_url.t @@ -257,23 +257,23 @@ if (!ok( $output = handle_server( ok( - it_url::get(['url' => "http://$host/not_found_with_body", 'empty_on_fail' => false, 'it_error' => false]), + it_url::get(['url' => "http://$host/not_found_with_body", 'body_on_fail' => true, 'it_error' => false]), 'it_url::get() on 404 with body' ) ); $output = handle_server( ok( - !it_url::get(['url' => "http://$host/not_found_with_body", 'empty_on_fail' => true, 'it_error' => false]), - 'it_url::get() on 404 with body and empty_on_fail' + !it_url::get(['url' => "http://$host/not_found_with_body", 'body_on_fail' => false, 'it_error' => false]), + 'it_url::get() on 404 with body and body_on_fail' ) ); $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'), + 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, empty_on_fail and assoc' + 'it_url::get() on 404 with body, body_on_fail and assoc' ) ); @@ -352,11 +352,11 @@ handle_server( "success" ), is( - it_url::get(['url' => "http://$host/maybe_error?chance=100", 'empty_on_fail' => false]), + it_url::get(['url' => "http://$host/maybe_error?chance=100", 'body_on_fail' => true]), "failure" ), is( - it_url::get(['url' => "http://$host/maybe_error?chance=25", 'empty_on_fail' => true, 'retries' => 10]), + it_url::get(['url' => "http://$host/maybe_error?chance=25", 'retries' => 10]), "success", "Retry on sporadically failing url in ::get" ), |