From 489510e7a9df2441cac820dc1d8e6b8410050b72 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 2 Oct 2019 03:45:32 +0000 Subject: [PATCH] Cache the header fields --- src/Network/CurlResult.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Network/CurlResult.php b/src/Network/CurlResult.php index a8dd3dd631..2f5c94187e 100644 --- a/src/Network/CurlResult.php +++ b/src/Network/CurlResult.php @@ -26,6 +26,11 @@ class CurlResult */ private $header; + /** + * @var array the HTTP headers of the Curl call + */ + private $header_fields; + /** * @var boolean true (if HTTP 2xx result) or false */ @@ -268,20 +273,21 @@ class CurlResult */ public function getHeaderArray() { - $headers = []; + if (!empty($this->header_fields)) { + return $this->header_fields; + } - $lines = explode("\n", $this->header); + $this->header_fields = []; + + $lines = explode("\n", trim($this->header)); foreach ($lines as $line) { $parts = explode(':', $line); $headerfield = strtolower(trim(array_shift($parts))); $headerdata = trim(implode(':', $parts)); - - if (!empty($headerdata)) { - $headers[$headerfield] = $headerdata; - } + $this->header_fields[$headerfield] = $headerdata; } - return $headers; + return $this->header_fields; } /** -- 2.39.5