Cache the header fields
This commit is contained in:
parent
5cdeb8615f
commit
489510e7a9
|
@ -26,6 +26,11 @@ class CurlResult
|
||||||
*/
|
*/
|
||||||
private $header;
|
private $header;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array the HTTP headers of the Curl call
|
||||||
|
*/
|
||||||
|
private $header_fields;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean true (if HTTP 2xx result) or false
|
* @var boolean true (if HTTP 2xx result) or false
|
||||||
*/
|
*/
|
||||||
|
@ -268,20 +273,21 @@ class CurlResult
|
||||||
*/
|
*/
|
||||||
public function getHeaderArray()
|
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) {
|
foreach ($lines as $line) {
|
||||||
$parts = explode(':', $line);
|
$parts = explode(':', $line);
|
||||||
$headerfield = strtolower(trim(array_shift($parts)));
|
$headerfield = strtolower(trim(array_shift($parts)));
|
||||||
$headerdata = trim(implode(':', $parts));
|
$headerdata = trim(implode(':', $parts));
|
||||||
|
$this->header_fields[$headerfield] = $headerdata;
|
||||||
if (!empty($headerdata)) {
|
|
||||||
$headers[$headerfield] = $headerdata;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $headers;
|
return $this->header_fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue