From 1b0864240055e7a09a315c7267937fda77d51391 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Fri, 4 May 2012 08:03:01 +0000
Subject: [PATCH] Utilities::fetch(): Handle reading files with getHeaders set
 to TRUE.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3085 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Utilities.php | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 4b1847e40..e6c80c4b3 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -2183,19 +2183,24 @@ class SimpleSAML_Utilities {
 		// Data and headers.
 		if ($getHeaders) {
 
-			$headers = array();
-
-			foreach($http_response_header as $h) {
-				if(preg_match('@^HTTP/1\.[01]\s+\d{3}\s+@', $h)) {
-					$headers = array(); // reset
-					$headers[0] = $h;
-					continue;
-				}
-				$bits = explode(':', $h, 2);
-				if(count($bits) === 2) {
-					$headers[strtolower($bits[0])] = trim($bits[1]);
+			if (isset($http_response_header)) {
+				$headers = array();
+				foreach($http_response_header as $h) {
+					if(preg_match('@^HTTP/1\.[01]\s+\d{3}\s+@', $h)) {
+						$headers = array(); // reset
+						$headers[0] = $h;
+						continue;
+					}
+					$bits = explode(':', $h, 2);
+					if(count($bits) === 2) {
+						$headers[strtolower($bits[0])] = trim($bits[1]);
+					}
 				}
+			} else {
+				/* No HTTP headers - probably a different protocol, e.g. file. */
+				$headers = NULL;
 			}
+
 			return array($data, $headers);
 		}
 
-- 
GitLab