summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Gass2024-10-21 19:12:19 +0200
committerNathan Gass2024-10-21 19:12:19 +0200
commit1c657c2264c17dc2980bbce2f63ddad7546e96d5 (patch)
treea555f7063ec459c37b68cd2987e14118a1bf8e2b
parent88cef74ff059c85e15ca5f9f9dff7c874780be58 (diff)
downloaditools-1c657c2264c17dc2980bbce2f63ddad7546e96d5.tar.gz
itools-1c657c2264c17dc2980bbce2f63ddad7546e96d5.tar.bz2
itools-1c657c2264c17dc2980bbce2f63ddad7546e96d5.zip
use CURLOPT_MAXFILESIZE now that we have current curl
-rw-r--r--it_url.class24
1 files changed, 6 insertions, 18 deletions
diff --git a/it_url.class b/it_url.class
index 8333f76..772b7d1 100644
--- a/it_url.class
+++ b/it_url.class
@@ -261,6 +261,9 @@ static function curl_opts($p=array())
if (isset($p['accept_encoding']))
$add += [CURLOPT_ENCODING => $p['accept_encoding']]; # NOTE: the curl library renamed the option to CURLOPT_ACCEPT_ENCODING, in php both are possible, CURLOPT_ENCODING is documented
+ if (isset($p['maxlength']))
+ $add += [CURLOPT_MAXFILESIZE => $p['maxlength']];
+
return $add + [
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
@@ -314,20 +317,6 @@ function request($p=array())
curl_setopt($curl, CURLOPT_URL, $url->url);
}
-
- // FIXME 2025-01 NG just use CURLOPT_MAXFILESIZE if we have curl 8.4
- $content = "";
- if ($p['maxlength'] && !$p['writefunction'])
- {
- $opts[CURLOPT_WRITEFUNCTION] = function ($dummy, $data) use ($p, &$content) {
- static $space;
- $write = min($space ??= $p['maxlength'], strlen($data));
- $content .= substr($data, 0, $write);
- $space -= $write;
- return $write;
- };
- }
-
$opts[CURLOPT_HEADERFUNCTION] = function ($dummy, $data) use (&$header) {
$header .= $data;
return strlen($data);
@@ -335,13 +324,12 @@ function request($p=array())
curl_setopt_array($curl, $opts);
- $got = curl_exec($curl);
- $body = $origbody = $p['maxlength'] && $got ? $content : $got;
+ $body = $origbody = curl_exec($curl);
$this->curlinfo = curl_getinfo($curl);
EDC('curlinfo', $this->curlinfo);
- if ($body !== false || curl_errno($curl) == 23)
+ if ($body !== false || curl_errno($curl) == 63)
{
$url->header = array_slice(explode("\r\n\r\n", trim($header)), -1)[0] . "\r\n\r\n";
$url->data = $body;
@@ -349,7 +337,7 @@ 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->status == 200 && strlen($content) && !$body)
+ if ($p['maxlength'] && $url->status == 200 && !$body)
$url->status = $this->result = 204;
if ($p['filemtime'] && ($url->status == 304))