summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-05-25 14:25:08 +0300
committerAndrew Dolgov <[email protected]>2018-05-25 14:25:08 +0300
commit68d9c412eaae9e61044a7e058610cc85ba7124f6 (patch)
tree2a63ba5df7dda555fe77e9fe5d78ea3e51adef47 /include
parent82152bdc34f9be021a57909b5ed21ad48a1275fb (diff)
fetch_file_contents: allow setting http Accept header
Diffstat (limited to 'include')
-rwxr-xr-xinclude/functions.php21
1 files changed, 15 insertions, 6 deletions
diff --git a/include/functions.php b/include/functions.php
index 6c8620f63..a6dbd43a8 100755
--- a/include/functions.php
+++ b/include/functions.php
@@ -376,6 +376,7 @@
$useragent = isset($options["useragent"]) ? $options["useragent"] : false;
$followlocation = isset($options["followlocation"]) ? $options["followlocation"] : true;
$max_size = isset($options["max_size"]) ? $options["max_size"] : MAX_DOWNLOAD_FILE_SIZE; // in bytes
+ $http_accept = isset($options["http_accept"]) ? $options["http_accept"] : false;
$url = ltrim($url, ' ');
$url = str_replace(' ', '%20', $url);
@@ -389,10 +390,16 @@
$ch = curl_init($url);
- if ($last_modified && !$post_query) {
- curl_setopt($ch, CURLOPT_HTTPHEADER,
- array("If-Modified-Since: $last_modified"));
- }
+ $curl_http_headers = [];
+
+ if ($last_modified && !$post_query)
+ array_push($curl_http_headers, "If-Modified-Since: $last_modified");
+
+ if ($http_accept)
+ array_push($curl_http_headers, "Accept: " . $http_accept);
+
+ if (count($curl_http_headers) > 0)
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_http_headers);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : FILE_FETCH_CONNECT_TIMEOUT);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : FILE_FETCH_TIMEOUT);
@@ -519,9 +526,11 @@
'protocol_version'=> 1.1)
);
- if (!$post_query && $last_modified) {
+ if (!$post_query && $last_modified)
array_push($context_options['http']['header'], "If-Modified-Since: $last_modified");
- }
+
+ if ($http_accept)
+ array_push($context_options['http']['header'], "Accept: $http_accept");
if (defined('_HTTP_PROXY')) {
$context_options['http']['request_fulluri'] = true;