]> git.wh0rd.org Git - tt-rss.git/commitdiff
Added propagation of $fetch_last_content_type for curl- and file_get_contents-calls
authorMarkus Birth <markus@birth-online.de>
Tue, 9 Apr 2013 22:59:48 +0000 (00:59 +0200)
committerMarkus Birth <markus@birth-online.de>
Tue, 9 Apr 2013 22:59:48 +0000 (00:59 +0200)
include/functions.php

index ddb719507c24df2f53157ee16da5a661b70e6c45..4ac4e09686e7ba65a7cd1184cddc13b4e5dfb503 100644 (file)
@@ -7,6 +7,7 @@
 
        $fetch_last_error = false;
        $fetch_last_error_code = false;
+       $fetch_last_content_type = false;
        $pluginhost = false;
 
        function __autoload($class) {
 
                global $fetch_last_error;
                global $fetch_last_error_code;
+               global $fetch_last_content_type;
 
                $url = str_replace(' ', '%20', $url);
 
                        }
 
                        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
-                       $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
+                       $fetch_last_content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
 
                        $fetch_last_error_code = $http_code;
 
-                       if ($http_code != 200 || $type && strpos($content_type, "$type") === false) {
+                       if ($http_code != 200 || $type && strpos($fetch_last_content_type, "$type") === false) {
                                if (curl_errno($ch) != 0) {
                                        $fetch_last_error = curl_errno($ch) . " " . curl_error($ch);
                                } else {
 
                        $data = @file_get_contents($url);
 
+                       $fetch_last_content_type = false;  // reset if no type was sent from server
+                       foreach ($http_response_header as $h) {
+                               if (substr(strtolower($h), 0, 13) == 'content-type:') {
+                                       $fetch_last_content_type = substr($h, 14);
+                                       // don't abort here b/c there might be more than one
+                                       // e.g. if we were being redirected -- last one is the right one
+                               }
+                       }
+
                        if (!$data && function_exists('error_get_last')) {
                                $error = error_get_last();
                                $fetch_last_error = $error["message"];