]> git.mxchange.org Git - friendica.git/commitdiff
New function to check for key existance
authorMichael <heluecht@pirati.ca>
Tue, 1 Oct 2019 21:46:18 +0000 (21:46 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 1 Oct 2019 21:46:18 +0000 (21:46 +0000)
src/Network/CurlResult.php

index 1c43db17d4abca58045fe3bd453da23653422ebe..06ca45fbce27dbe716b25fc355fbf5e4e5e037a1 100644 (file)
@@ -236,16 +236,29 @@ class CurlResult
                        return $this->header;
                }
 
-               $lines = explode("\n", $this->header);
-               foreach ($lines as $line) {
-                       $parts = explode(':', $line);
-                       $headerfield = array_shift($parts);
-                       if (strtolower(trim($field)) == strtolower(trim($headerfield))) {
-                               return trim(implode(':', $parts));
-                       }
+               $field = strtolower(trim($field));
+
+               $headers = self::getHeaderArray();
+
+               if (isset($headers[$field])) {
+                       return $headers[$field];
                }
+       }
+
+       /**
+        * Check if a specified header exists
+        *
+        * @param string $field header field
+        *
+        * @return boolean "true" if header exists
+        */
+       public function headerExists(string $field)
+       {
+               $field = strtolower(trim($field));
+
+               $headers = self::getHeaderArray();
 
-               return '';
+               return array_key_exists($field, $headers);
        }
 
        /**