diff options
author | Nathan Gass | 2023-10-30 17:47:27 +0100 |
---|---|---|
committer | Nathan Gass | 2023-10-30 17:47:27 +0100 |
commit | f75da376ff31eed20e409797260ba832be3b9308 (patch) | |
tree | 15b31ef4f516af8a880e65c4450497f7c5d705ac /it_url.class | |
parent | af3d6d4c2105ff832817923672129347dfbe93ff (diff) | |
download | itools-f75da376ff31eed20e409797260ba832be3b9308.tar.gz itools-f75da376ff31eed20e409797260ba832be3b9308.tar.bz2 itools-f75da376ff31eed20e409797260ba832be3b9308.zip |
simplify maxlength implementation and make compatible with writefunction
Diffstat (limited to 'it_url.class')
-rw-r--r-- | it_url.class | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/it_url.class b/it_url.class index facf78d..e79d894 100644 --- a/it_url.class +++ b/it_url.class @@ -306,18 +306,12 @@ function request($p=array()) // FIXME 2025-01 NG just use CURLOPT_MAXFILESIZE if we have curl 8.4 - if ($p['maxlength'] && !$p['writefunction']) + if ($p['maxlength']) { - $content = ""; - $opts[CURLOPT_WRITEFUNCTION] = function ($dummy, $data) use ($p, &$content) { - static $total = 0; - $size = strlen($data); - $total += $size; - if ($total > $p['maxlength']) - return 0; - $content .= $data; - return $size; + $opts[CURLOPT_XFERINFOFUNCTION] = function ($dummy, $dummy2, $total) use ($p) { + return $total < $p['maxlength'] ? 0 : 1; }; + $opts[CURLOPT_NOPROGRESS] = 0; } $opts[CURLOPT_HEADERFUNCTION] = function ($dummy, $data) use (&$header) { @@ -329,9 +323,6 @@ function request($p=array()) $got = curl_exec($curl); - if ($p['maxlength'] && $got) - $got = $content; - $this->curlinfo = curl_getinfo($curl); EDC('curlinfo', $this->curlinfo); |