summaryrefslogtreecommitdiff
path: root/it_url.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_url.class')
-rw-r--r--it_url.class18
1 files changed, 10 insertions, 8 deletions
diff --git a/it_url.class b/it_url.class
index a94975d..83ea9fb 100644
--- a/it_url.class
+++ b/it_url.class
@@ -305,17 +305,15 @@ function request($p=array())
// FIXME 2025-01 NG just use CURLOPT_MAXFILESIZE if we have curl 8.4
+ $content = "";
if ($p['maxlength'] && !$p['writefunction'])
{
- $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;
+ static $space;
+ $write = min($space ?? $p['maxlength'], strlen($data));
+ $content .= substr($data, 0, $write);
+ $space -= $write;
+ return $write;
};
}
@@ -341,6 +339,10 @@ 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->result == 200 && strlen($content) && !$got)
+ $url->result = 204;
+
if ($p['filemtime'] && ($url->result == 304))
{
$result = true; # Not modified, success but no data