From 516fd02812b0ac86fd6cbc6d2f4d9adb58d959a9 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 1 Oct 2019 21:46:18 +0000 Subject: [PATCH] New function to check for key existance --- src/Network/CurlResult.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Network/CurlResult.php b/src/Network/CurlResult.php index 1c43db17d..06ca45fbc 100644 --- a/src/Network/CurlResult.php +++ b/src/Network/CurlResult.php @@ -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)); - return ''; + $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 array_key_exists($field, $headers); } /**