diff options
author | Urban Müller | 2024-06-27 15:39:48 +0200 |
---|---|---|
committer | Urban Müller | 2024-06-27 15:39:48 +0200 |
commit | b50b0b3ae13fc22c878c29ae49299ca41a7ebbed (patch) | |
tree | 83d4a7e2d620dda14377445ff5a2726396ff9fa9 | |
parent | 1f03ed8e2d653851ef276ef5d84546e1dced2335 (diff) | |
download | itools-b50b0b3ae13fc22c878c29ae49299ca41a7ebbed.tar.gz itools-b50b0b3ae13fc22c878c29ae49299ca41a7ebbed.tar.bz2 itools-b50b0b3ae13fc22c878c29ae49299ca41a7ebbed.zip |
add response body to errors, rename $got to $body
-rw-r--r-- | it_url.class | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/it_url.class b/it_url.class index 3d1d164..ec20335 100644 --- a/it_url.class +++ b/it_url.class @@ -331,22 +331,20 @@ function request($p=array()) curl_setopt_array($curl, $opts); $got = curl_exec($curl); - - if ($p['maxlength'] && $got) - $got = $content; + $body = $origbody = $p['maxlength'] && $got ? $content : $got; $this->curlinfo = curl_getinfo($curl); EDC('curlinfo', $this->curlinfo); - if ($got !== false || curl_errno($curl) == 23) + if ($body !== false || curl_errno($curl) == 23) { $url->header = array_slice(explode("\r\n\r\n", trim($header)), -1)[0] . "\r\n\r\n"; - $url->data = $got; + $url->data = $body; $url->parse_http_header($url->header); # Change result status for content longer than maxlength to 204 as we do not return partial data but still want to indicate success e.g. for is_reachable - if ($p['maxlength'] && $url->result == 200 && strlen($content) && !$got) + if ($p['maxlength'] && $url->result == 200 && strlen($content) && !$body) $url->result = 204; if ($p['filemtime'] && ($url->result == 304)) @@ -361,7 +359,7 @@ function request($p=array()) else { if ($url->result >= 400 && (!$p['body_on_fail'] || $p['keepfailed'])) - $got = $url->data = false; + $body = $url->data = false; $result =& $url->data; $this->errstr = "HTTP Status " . $url->result; } @@ -379,9 +377,12 @@ function request($p=array()) fclose($stderr); } - if ($got === false && $p['retries'] <= 0) + if ($body === false && $p['retries'] <= 0) { - it::error((array)$p['it_error'] + ['title' => "problem " . ($p['method'] ?: "gett") . "ing $url->url: " . $this->errstr, 'body' => curl_getinfo($curl) + ($p['verbose'] ? ['verbose' => $this->verbose] : [])]); + it::error((array)$p['it_error'] + [ + 'title' => "problem " . ($p['method'] ?: "gett") . "ing $url->url: " . $this->errstr, + 'body' => $this->curlinfo + ($p['verbose'] ? ['verbose' => $this->verbose] : []) + ['body' => @grapheme_substr($origbody, 0, 2000)], + ]); } return $result; |