summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2019-03-01 16:50:40 +0100
committerUrban Müller2019-03-01 16:50:40 +0100
commita648b594c6a96f050b99eb691c73b41f27d6890b (patch)
treeb48c2ddbbee92c120bd5ecac5d58ba06fcee780b
parentfbca4d57db71cfbd5d9ef52a32ccd8688a37b3ce (diff)
downloaditools-a648b594c6a96f050b99eb691c73b41f27d6890b.tar.gz
itools-a648b594c6a96f050b99eb691c73b41f27d6890b.tar.bz2
itools-a648b594c6a96f050b99eb691c73b41f27d6890b.zip
better name for http status variable
-rw-r--r--it_url.class17
-rwxr-xr-xtest/it_url.t5
2 files changed, 15 insertions, 7 deletions
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;
}
diff --git a/test/it_url.t b/test/it_url.t
index eb36dd6..4243f33 100755
--- a/test/it_url.t
+++ b/test/it_url.t
@@ -138,6 +138,11 @@ ok(
'$url->get(\'url\' => url) with url as named arg'
);
is(
+ $url->status,
+ '200',
+ '$url->status = 200'
+);
+is(
$url->result,
'200',
'$url->result = 200'