diff --git a/public/lib/filelib.php b/public/lib/filelib.php index e46df988fce..840ed79b6aa 100644 --- a/public/lib/filelib.php +++ b/public/lib/filelib.php @@ -3639,6 +3639,10 @@ class curl { $options[$n] = $v; } $handles[$i] = curl_init($requests[$i]['url']); + + // Set the URL as a curl option. + $this->setopt(['CURLOPT_URL' => $requests[$i]['url']]); + $this->apply_opt($handles[$i], $options); curl_multi_add_handle($main, $handles[$i]); } diff --git a/public/lib/tests/filelib_test.php b/public/lib/tests/filelib_test.php index f0414ad7473..ae7a87edb09 100644 --- a/public/lib/tests/filelib_test.php +++ b/public/lib/tests/filelib_test.php @@ -511,6 +511,27 @@ final class filelib_test extends \advanced_testcase { $this->assertNotEquals(0, $curl->get_errno()); $this->assertNotEquals('47250a973d1b88d9445f94db4ef2c97a', md5($contents)); + // Test multiple queries with proxy. + $curl = new \curl(['debug' => 1]); + ob_start(); + $requests = [[ + 'nobody' => true, + 'header' => 1, + 'url' => $testurl, + 'returntransfer' => true, + ], + [ + 'nobody' => true, + 'header' => 1, + 'url' => $testurl, + 'returntransfer' => true, + ]]; + $curl->download($requests); + $output = ob_get_contents(); + ob_end_clean(); + // We must have exactly 2 occurrences of ["CURLOPT_PROXY"]. + $this->assertMatchesRegularExpression('/(\["CURLOPT_PROXY"\].*){2}/ms', $output); + // Test with proxy bypass. $testurlhost = parse_url($testurl, PHP_URL_HOST); $CFG->proxybypass = $testurlhost; @@ -519,6 +540,26 @@ final class filelib_test extends \advanced_testcase { $this->assertSame(0, $curl->get_errno()); $this->assertSame('47250a973d1b88d9445f94db4ef2c97a', md5($contents)); + // Test multiple queries with proxy bypass. + $curl = new \curl(['debug' => 1]); + ob_start(); + $requests = [[ + 'nobody' => true, + 'header' => 1, + 'url' => $testurl, + 'returntransfer' => true, + ], + [ + 'nobody' => true, + 'header' => 1, + 'url' => $testurl, + 'returntransfer' => true, + ]]; + $curl->download($requests); + $output = ob_get_contents(); + ob_end_clean(); + $this->assertStringNotContainsString('["CURLOPT_PROXY"]', $output); + $CFG->proxyhost = $oldproxy; $CFG->proxybypass = $oldproxybypass; }