From b50b0b3ae13fc22c878c29ae49299ca41a7ebbed Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 27 Jun 2024 15:39:48 +0200 Subject: add response body to errors, rename $got to $body --- it_url.class | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'it_url.class') 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; -- cgit v1.2.3