From 18198b4aaa925c2cff83100bba3c072d2dd624e5 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 1 Oct 2019 16:33:11 +0000 Subject: [PATCH] Enable the possibility to fetch a specific header variable --- src/Network/CurlResult.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Network/CurlResult.php b/src/Network/CurlResult.php index 1a475c7ce..998644a87 100644 --- a/src/Network/CurlResult.php +++ b/src/Network/CurlResult.php @@ -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; } /**