diff options
author | Nathan Gass | 2023-11-13 16:04:15 +0100 |
---|---|---|
committer | Nathan Gass | 2023-11-13 16:04:15 +0100 |
commit | d7b0fbd38f80a80424bf3645564eb3b9f9cc78fe (patch) | |
tree | 7715f03b41b07497fbc6b65232c5d3886637cf63 /it_url.class | |
parent | 7599cb89f649be5685d05a409ab216c7b183feef (diff) | |
download | itools-d7b0fbd38f80a80424bf3645564eb3b9f9cc78fe.tar.gz itools-d7b0fbd38f80a80424bf3645564eb3b9f9cc78fe.tar.bz2 itools-d7b0fbd38f80a80424bf3645564eb3b9f9cc78fe.zip |
Revert "simplify maxlength implementation and make compatible with writefunction"
This reverts commit f75da376ff31eed20e409797260ba832be3b9308.
Diffstat (limited to 'it_url.class')
-rw-r--r-- | it_url.class | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/it_url.class b/it_url.class index 25f4eee..2b3df72 100644 --- a/it_url.class +++ b/it_url.class @@ -306,12 +306,18 @@ function request($p=array()) // FIXME 2025-01 NG just use CURLOPT_MAXFILESIZE if we have curl 8.4 - if ($p['maxlength']) + if ($p['maxlength'] && !$p['writefunction']) { - $opts[CURLOPT_XFERINFOFUNCTION] = function ($dummy, $dummy2, $total) use ($p) { - return $total < $p['maxlength'] ? 0 : 1; + $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_NOPROGRESS] = 0; } $opts[CURLOPT_HEADERFUNCTION] = function ($dummy, $data) use (&$header) { @@ -323,6 +329,9 @@ function request($p=array()) $got = curl_exec($curl); + if ($p['maxlength'] && $got) + $got = $content; + $this->curlinfo = curl_getinfo($curl); EDC('curlinfo', $this->curlinfo); |