From a648b594c6a96f050b99eb691c73b41f27d6890b Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Fri, 1 Mar 2019 16:50:40 +0100 Subject: better name for http status variable --- it_url.class | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'it_url.class') diff --git a/it_url.class b/it_url.class index 7b364d2..affd38a 100644 --- a/it_url.class +++ b/it_url.class @@ -34,8 +34,9 @@ class it_url var $pass; /* E.g. joshua */ 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 $data; /* Data part, even if http status code is not 200 */ + var $result; /* DEPRECATED, see $status */ + var $status; /* HTTP status code of last get() */ var $redir = 0; /* Redirect count */ var $header; /* http header */ var $errstr; /* request error string */ @@ -131,7 +132,7 @@ function get($p=null, $timeout=5) $result = $url->request($p + ['followlocation' => true]); - if (!$result && $p['retries'] > 0 && $url->result < 400) + if (!$result && $p['retries'] > 0 && $url->status < 400) { usleep($p['retrysleep']*1000000); $result = $url->get(array('retries' => $p['retries'] - 1) + $p); @@ -150,7 +151,7 @@ function parse_http_header($header) foreach (explode("\n", trim($header)) as $line) { $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 = $parts[2]; elseif (preg_match('#^([^:]+): (.*)$#', $line, $parts)) $this->headers[$parts[1]] = $parts[2]; if ($parts[1] == 'Set-Cookie' && preg_match('/^([^=]+)=([^;]*)/', $parts[2], $cookie)) @@ -274,15 +275,15 @@ function request($p=array()) $url->parse_http_header($url->header); if ($p['maxlength'] && (strlen($this->data) > $p['maxlength'])) { - $result = $this->result = false; + $result = $this->status = false; $this->errstr = "maxlength reached"; - } else if ($p['filemtime'] && ($url->result == 304)) { + } else if ($p['filemtime'] && ($url->status == 304)) { $result = true; # Not modified, success but no data } else { $result =& $url->data; } } else { - $result = $this->result = false; + $result = $this->status = false; $this->errstr = trim("(" . curl_errno($curl) . ") " . curl_error($curl)); $this->curlinfo = curl_getinfo($curl); } @@ -297,6 +298,8 @@ function request($p=array()) it::error((array)$p['it_error'] + ['title' => "problem getting $url->url with curl: (" . curl_errno($curl) . ") " . curl_error($curl), 'body' => curl_getinfo($curl) + ($p['verbose'] ? ['verbose' => $this->verbose] : [])]); } + $url->result = $url->status; # FIXME 2019-06-01 get rid of remaining uses + return $result; } -- cgit v1.2.3