diff options
author | Aurélien Tamisier <virtualtam+github@flibidi.net> | 2018-12-02 22:47:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-02 22:47:41 +0100 |
commit | 1004742f09b55ff781c13745781b9a7e90986faa (patch) | |
tree | aa0e5743390296441edf09f44f95b3d21f2b5a16 /application/HttpUtils.php | |
parent | 5e0a898bb13fad528514b0d33763bcaae38b45b0 (diff) | |
parent | 9d9f6d75b94aab51067bdfbe50b58b66d1194f6d (diff) | |
download | Shaarli-1004742f09b55ff781c13745781b9a7e90986faa.tar.gz Shaarli-1004742f09b55ff781c13745781b9a7e90986faa.tar.zst Shaarli-1004742f09b55ff781c13745781b9a7e90986faa.zip |
Merge pull request #1234 from virtualtam/lint
Setup PHPCS and cleanup linter configuration
Diffstat (limited to 'application/HttpUtils.php')
-rw-r--r-- | application/HttpUtils.php | 29 |
1 files changed, 15 insertions, 14 deletions
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 @@ | |||
7 | * @param int $timeout network timeout (in seconds) | 7 | * @param int $timeout network timeout (in seconds) |
8 | * @param int $maxBytes maximum downloaded bytes (default: 4 MiB) | 8 | * @param int $maxBytes maximum downloaded bytes (default: 4 MiB) |
9 | * @param callable|string $curlWriteFunction Optional callback called during the download (cURL CURLOPT_WRITEFUNCTION). | 9 | * @param callable|string $curlWriteFunction Optional callback called during the download (cURL CURLOPT_WRITEFUNCTION). |
10 | * Can be used to add download conditions on the headers (response code, content type, etc.). | 10 | * Can be used to add download conditions on the |
11 | * headers (response code, content type, etc.). | ||
11 | * | 12 | * |
12 | * @return array HTTP response headers, downloaded content | 13 | * @return array HTTP response headers, downloaded content |
13 | * | 14 | * |
@@ -64,29 +65,30 @@ function get_http_response($url, $timeout = 30, $maxBytes = 4194304, $curlWriteF | |||
64 | } | 65 | } |
65 | 66 | ||
66 | // General cURL settings | 67 | // General cURL settings |
67 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); | 68 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
68 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | 69 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
69 | curl_setopt($ch, CURLOPT_HEADER, true); | 70 | curl_setopt($ch, CURLOPT_HEADER, true); |
70 | curl_setopt( | 71 | curl_setopt( |
71 | $ch, | 72 | $ch, |
72 | CURLOPT_HTTPHEADER, | 73 | CURLOPT_HTTPHEADER, |
73 | array('Accept-Language: ' . $acceptLanguage) | 74 | array('Accept-Language: ' . $acceptLanguage) |
74 | ); | 75 | ); |
75 | curl_setopt($ch, CURLOPT_MAXREDIRS, $maxRedirs); | 76 | curl_setopt($ch, CURLOPT_MAXREDIRS, $maxRedirs); |
76 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 77 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
77 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); | 78 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
78 | curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); | 79 | curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); |
79 | 80 | ||
80 | if (is_callable($curlWriteFunction)) { | 81 | if (is_callable($curlWriteFunction)) { |
81 | curl_setopt($ch, CURLOPT_WRITEFUNCTION, $curlWriteFunction); | 82 | curl_setopt($ch, CURLOPT_WRITEFUNCTION, $curlWriteFunction); |
82 | } | 83 | } |
83 | 84 | ||
84 | // Max download size management | 85 | // Max download size management |
85 | curl_setopt($ch, CURLOPT_BUFFERSIZE, 1024*16); | 86 | curl_setopt($ch, CURLOPT_BUFFERSIZE, 1024*16); |
86 | curl_setopt($ch, CURLOPT_NOPROGRESS, false); | 87 | curl_setopt($ch, CURLOPT_NOPROGRESS, false); |
87 | curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, | 88 | curl_setopt( |
88 | function($arg0, $arg1, $arg2, $arg3, $arg4 = 0) use ($maxBytes) | 89 | $ch, |
89 | { | 90 | CURLOPT_PROGRESSFUNCTION, |
91 | function ($arg0, $arg1, $arg2, $arg3, $arg4 = 0) use ($maxBytes) { | ||
90 | if (version_compare(phpversion(), '5.5', '<')) { | 92 | if (version_compare(phpversion(), '5.5', '<')) { |
91 | // PHP version lower than 5.5 | 93 | // PHP version lower than 5.5 |
92 | // Callback has 4 arguments | 94 | // Callback has 4 arguments |
@@ -232,7 +234,6 @@ function get_redirected_headers($url, $redirectionLimit = 3) | |||
232 | && !empty($headers) | 234 | && !empty($headers) |
233 | && (strpos($headers[0], '301') !== false || strpos($headers[0], '302') !== false) | 235 | && (strpos($headers[0], '301') !== false || strpos($headers[0], '302') !== false) |
234 | && !empty($headers['Location'])) { | 236 | && !empty($headers['Location'])) { |
235 | |||
236 | $redirection = is_array($headers['Location']) ? end($headers['Location']) : $headers['Location']; | 237 | $redirection = is_array($headers['Location']) ? end($headers['Location']) : $headers['Location']; |
237 | if ($redirection != $url) { | 238 | if ($redirection != $url) { |
238 | $redirection = getAbsoluteUrl($url, $redirection); | 239 | $redirection = getAbsoluteUrl($url, $redirection); |