]> git.mxchange.org Git - friendica.git/commitdiff
Enable the possibility to fetch a specific header variable
authorMichael <heluecht@pirati.ca>
Tue, 1 Oct 2019 16:33:11 +0000 (16:33 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 1 Oct 2019 16:33:11 +0000 (16:33 +0000)
src/Network/CurlResult.php

index 1a475c7cec959983a2c5312a806ab29aa8b3e76b..998644a8765fb8501b2b64ae5a2f744e9c4d4d81 100644 (file)
@@ -226,11 +226,26 @@ class CurlResult
        /**
         * Returns the Curl headers
         *
-        * @return string the Curl headers
+        * @param string $field optional header field. Return all fields if empty
+        *
+        * @return string|bool the Curl headers, "false" when field isn't found
         */
-       public function getHeader()
+       public function getHeader($field = '')
        {
-               return $this->header;
+               if (empty($field)) {
+                       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 implode(':', $parts);
+                       }
+               }
+
+               return false;
        }
 
        /**