From 134e639995c9a7a930da31c5b615d51997d0d177 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Mon, 27 May 2024 15:10:38 +0200 Subject: Fix it_url::get with maxlength and large response --- it_url.class | 2 +- test/it_url_slow.t | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/it_url.class b/it_url.class index 953562d..01913e3 100644 --- a/it_url.class +++ b/it_url.class @@ -316,7 +316,7 @@ function request($p=array()) { $opts[CURLOPT_WRITEFUNCTION] = function ($dummy, $data) use ($p, &$content) { static $space; - $write = min($space ?? $p['maxlength'], strlen($data)); + $write = min($space ??= $p['maxlength'], strlen($data)); $content .= substr($data, 0, $write); $space -= $write; return $write; diff --git a/test/it_url_slow.t b/test/it_url_slow.t index 59afe7e..b382b3a 100755 --- a/test/it_url_slow.t +++ b/test/it_url_slow.t @@ -74,6 +74,14 @@ handle_server( ) ); + +handle_server( + ok( + it_url::get('url' => U("http://$host/repeat", ['string' => "abc", 'num' => 1024 * 32]), 'maxlength' => 1024 * 1024) == str_repeat("abc", 1024 * 32), + 'it_url::get() handles large response with maxlength set' + ) +); + $start = microtime(true); it_url::get_multi(['urls' => ['slow' => "http://$host/long_sleep", 'fast' => ['url' => 'http://search.ch/', 'handler' => function () {return true;}]]]); ok(intval(microtime(true) - $start) < 4, 'get_multi with handler aborts after fast request'); -- cgit v1.2.3