X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FHttpUtils.php;h=9c438160dccdbe022d1f5398b41f27162774643f;hb=1004742f09b55ff781c13745781b9a7e90986faa;hp=e9282506188f4d19969e9a49ac27664171c79938;hpb=0deaedeeaef088040fb015f5be3e270e3bae508e;p=github%2Fshaarli%2FShaarli.git diff --git a/application/HttpUtils.php b/application/HttpUtils.php index e9282506..9c438160 100644 --- a/application/HttpUtils.php +++ b/application/HttpUtils.php @@ -7,7 +7,8 @@ * @param int $timeout network timeout (in seconds) * @param int $maxBytes maximum downloaded bytes (default: 4 MiB) * @param callable|string $curlWriteFunction Optional callback called during the download (cURL CURLOPT_WRITEFUNCTION). - * Can be used to add download conditions on the headers (response code, content type, etc.). + * Can be used to add download conditions on the + * headers (response code, content type, etc.). * * @return array HTTP response headers, downloaded content * @@ -64,29 +65,30 @@ function get_http_response($url, $timeout = 30, $maxBytes = 4194304, $curlWriteF } // General cURL settings - curl_setopt($ch, CURLOPT_AUTOREFERER, true); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_AUTOREFERER, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Accept-Language: ' . $acceptLanguage) ); - curl_setopt($ch, CURLOPT_MAXREDIRS, $maxRedirs); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); - curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); + curl_setopt($ch, CURLOPT_MAXREDIRS, $maxRedirs); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); if (is_callable($curlWriteFunction)) { curl_setopt($ch, CURLOPT_WRITEFUNCTION, $curlWriteFunction); } // Max download size management - curl_setopt($ch, CURLOPT_BUFFERSIZE, 1024*16); - curl_setopt($ch, CURLOPT_NOPROGRESS, false); - curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, - function($arg0, $arg1, $arg2, $arg3, $arg4 = 0) use ($maxBytes) - { + curl_setopt($ch, CURLOPT_BUFFERSIZE, 1024*16); + curl_setopt($ch, CURLOPT_NOPROGRESS, false); + curl_setopt( + $ch, + CURLOPT_PROGRESSFUNCTION, + function ($arg0, $arg1, $arg2, $arg3, $arg4 = 0) use ($maxBytes) { if (version_compare(phpversion(), '5.5', '<')) { // PHP version lower than 5.5 // Callback has 4 arguments @@ -232,7 +234,6 @@ function get_redirected_headers($url, $redirectionLimit = 3) && !empty($headers) && (strpos($headers[0], '301') !== false || strpos($headers[0], '302') !== false) && !empty($headers['Location'])) { - $redirection = is_array($headers['Location']) ? end($headers['Location']) : $headers['Location']; if ($redirection != $url) { $redirection = getAbsoluteUrl($url, $redirection);