Merged MDL-27251 Fixed up whitespace, Fixed broken string, reworded new strings
This commit is contained in:
+39
-7
@@ -904,7 +904,6 @@ function format_postdata_for_curlcall($postdata) {
|
||||
* Fetches content of file from Internet (using proxy if defined). Uses cURL extension if present.
|
||||
* Due to security concerns only downloads from http(s) sources are supported.
|
||||
*
|
||||
* @global object
|
||||
* @param string $url file url starting with http(s)://
|
||||
* @param array $headers http headers, null if none. If set, should be an
|
||||
* associative array of header name => value pairs.
|
||||
@@ -916,11 +915,14 @@ function format_postdata_for_curlcall($postdata) {
|
||||
* @param int $connecttimeout timeout for connection to server; this is the timeout that
|
||||
* usually happens if the remote server is completely down (default 20 seconds);
|
||||
* may not work when using proxy
|
||||
* @param bool $skipcertverify If true, the peer's SSL certificate will not be checked. Only use this when already in a trusted location.
|
||||
* @param string $tofile store the downloaded content to file instead of returning it
|
||||
* @return mixed false if request failed or content of the file as string if ok. true if file downloaded into $tofile successfully.
|
||||
* @param bool $skipcertverify If true, the peer's SSL certificate will not be checked.
|
||||
* Only use this when already in a trusted location.
|
||||
* @param string $tofile store the downloaded content to file instead of returning it.
|
||||
* @param bool $calctimeout false by default, true enables an extra head request to try and determine
|
||||
* filesize and appropriately larger timeout based on $CFG->curltimeoutkbitrate
|
||||
* @return mixed false if request failed or content of the file as string if ok. True if file downloaded into $tofile successfully.
|
||||
*/
|
||||
function download_file_content($url, $headers=null, $postdata=null, $fullresponse=false, $timeout=300, $connecttimeout=20, $skipcertverify=false, $tofile=NULL) {
|
||||
function download_file_content($url, $headers=null, $postdata=null, $fullresponse=false, $timeout=300, $connecttimeout=20, $skipcertverify=false, $tofile=NULL, $calctimeout=false) {
|
||||
global $CFG;
|
||||
|
||||
// some extra security
|
||||
@@ -962,7 +964,6 @@ function download_file_content($url, $headers=null, $postdata=null, $fullrespons
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers2);
|
||||
}
|
||||
|
||||
|
||||
if ($skipcertverify) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
}
|
||||
@@ -977,7 +978,7 @@ function download_file_content($url, $headers=null, $postdata=null, $fullrespons
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connecttimeout);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
|
||||
if (!ini_get('open_basedir') and !ini_get('safe_mode')) {
|
||||
// TODO: add version test for '7.10.5'
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
@@ -1033,6 +1034,37 @@ function download_file_content($url, $headers=null, $postdata=null, $fullrespons
|
||||
curl_setopt($ch, CURLOPT_WRITEFUNCTION, partial('download_file_content_write_handler', $received));
|
||||
}
|
||||
|
||||
if (!isset($CFG->curltimeoutkbitrate)) {
|
||||
//use very slow rate of 56kbps as a timeout speed when not set
|
||||
$bitrate = 56;
|
||||
} else {
|
||||
$bitrate = $CFG->curltimeoutkbitrate;
|
||||
}
|
||||
|
||||
// try to calculate the proper amount for timeout from remote file size.
|
||||
// if disabled or zero, we won't do any checks nor head requests.
|
||||
if ($calctimeout && $bitrate > 0) {
|
||||
//setup header request only options
|
||||
curl_setopt_array ($ch, array(
|
||||
CURLOPT_RETURNTRANSFER => false,
|
||||
CURLOPT_NOBODY => true)
|
||||
);
|
||||
|
||||
curl_exec($ch);
|
||||
$info = curl_getinfo($ch);
|
||||
$err = curl_error($ch);
|
||||
|
||||
if ($err === '' && $info['download_content_length'] > 0) { //no curl errors
|
||||
$timeout = max($timeout, ceil($info['download_content_length'] * 8 / ($bitrate * 1024))); //adjust for large files only - take max timeout.
|
||||
}
|
||||
//reinstate affected curl options
|
||||
curl_setopt_array ($ch, array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_NOBODY => false)
|
||||
);
|
||||
}
|
||||
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
||||
$result = curl_exec($ch);
|
||||
|
||||
// try to detect encoding problems
|
||||
|
||||
Reference in New Issue
Block a user