diff options
author | Urban Müller | 2024-07-04 14:36:22 +0200 |
---|---|---|
committer | Urban Müller | 2024-07-04 14:36:22 +0200 |
commit | b9be6472b1236f566015a1537f516d638635719e (patch) | |
tree | 13909fcc8e7cf606db80d5ee49bb79984c0ac22e | |
parent | 0f3b884db2baa72b87eb9c32ecdf03649598ae81 (diff) | |
download | itools-b9be6472b1236f566015a1537f516d638635719e.tar.gz itools-b9be6472b1236f566015a1537f516d638635719e.tar.bz2 itools-b9be6472b1236f566015a1537f516d638635719e.zip |
introduce ->status for ->result, temporarily support ->result
-rw-r--r-- | it_url.class | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/it_url.class b/it_url.class index c2d7faf..de20007 100644 --- a/it_url.class +++ b/it_url.class @@ -35,7 +35,8 @@ class it_url var $cookies; /* key => values of cookies from server */ var $headers; /* Headers of page fetched by get() */ var $data; /* Data part, even if return code is not 200 */ - var $result; /* HTTP response code of get() */ + var $status; /* HTTP response code of get() */ + var $result; /* Deprecated, copy of $status */ var $redir = 0; /* Redirect count */ var $header; /* http header */ var $errstr; /* request error string */ @@ -143,7 +144,7 @@ function _get($p = []) $result = $this->request($p + ['followlocation' => true]); $result = self::_postprocess($result, $p); - if ($p['retries'] > 0 && self::retry_warranted($result, $this->result)) + if ($p['retries'] > 0 && self::retry_warranted($result, $this->status)) { usleep($p['retrysleep']*1000000); $result = $this->_get(array('retries' => $p['retries'] - 1) + $p); @@ -155,9 +156,9 @@ function _get($p = []) usleep($p['fetchsleep'] * 1000000); if ($p['assoc']) - $result = [ 'status' => intval($this->result) ?: 503, 'data' => $result !== false ? $this->data : null, 'headers' => $this->headers, 'cookies' => $this->cookies, 'errstr' => $this->errstr ]; + $result = [ 'status' => intval($this->status) ?: 503, 'data' => $result !== false ? $this->data : null, 'headers' => $this->headers, 'cookies' => $this->cookies, 'errstr' => $this->errstr ]; - EDC('curlinfo', $this->result, $this->headers, $this->cookies, $this->errstr); + EDC('curlinfo', $this->status, $this->headers, $this->cookies, $this->errstr); return $result; } @@ -173,7 +174,7 @@ function parse_http_header($header) { $line = trim($line); if (preg_match('#^(HTTP)\S+\s(\d+)#', $line, $parts)) # Parse result code - $this->headers[$parts[1]] = $this->result = $parts[2]; + $this->headers[$parts[1]] = $this->status = $this->result = $parts[2]; else if (preg_match('#^([^:]+): (.*)$#', $line, $parts)) $this->headers[ucwords($parts[1], '-')] = $parts[2]; if (strtolower($parts[1]) == 'set-cookie' && preg_match('/^([^=]+)=([^;]*)/', $parts[2], $cookie)) @@ -348,29 +349,29 @@ function request($p=array()) $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) && !$body) - $url->result = 204; + if ($p['maxlength'] && $url->status == 200 && strlen($content) && !$body) + $url->status = $this->result = 204; - if ($p['filemtime'] && ($url->result == 304)) + if ($p['filemtime'] && ($url->status == 304)) { $result = true; # Not modified, success but no data } - else if ($url->result == 414) + else if ($url->status == 414) { it::error((array)$p['it_error'] + ['title' => "Request-URI Too Long: " . substr($url->url, 0, 100) . "...(truncated " . (strlen($url->url) - 100) . " bytes)", 'body' => curl_getinfo($curl) + ($p['verbose'] ? ['verbose' => $this->verbose] : [])]); - $this->errstr = "HTTP Status " . $url->result; + $this->errstr = "HTTP Status " . $url->status; } else { - if ($url->result >= 400 && (!$p['body_on_fail'] || $p['keepfailed'])) + if ($url->status >= 400 && (!$p['body_on_fail'] || $p['keepfailed'])) $body = $url->data = false; $result =& $url->data; - $this->errstr = "HTTP Status " . $url->result; + $this->errstr = "HTTP Status " . $url->status; } } else { - $result = $this->result = false; + $result = $this->status = $this->result = false; $this->errstr = trim(curl_strerror(curl_errno($curl)) . "(" . curl_errno($curl) . ") " . curl_error($curl)); } @@ -381,7 +382,7 @@ function request($p=array()) fclose($stderr); } - if ($body === false && $p['retries'] <= 0 && self::retry_warranted($result, $this->result)) + if ($body === false && $p['retries'] <= 0 && self::retry_warranted($result, $this->status)) { it::error((array)$p['it_error'] + [ 'title' => "problem " . ($p['method'] ?: "gett") . "ing $url->url: " . $this->errstr, |