+ if (empty($field)) {
+ return $this->header;
+ }
+
+ $field = strtolower(trim($field));
+
+ $headers = $this->getHeaderArray();
+
+ if (isset($headers[$field])) {
+ return $headers[$field];
+ }
+
+ return '';
+ }
+
+ /**
+ * Check if a specified header exists
+ *
+ * @param string $field header field
+ *
+ * @return boolean "true" if header exists
+ */
+ public function inHeader(string $field)
+ {
+ $field = strtolower(trim($field));
+
+ $headers = $this->getHeaderArray();
+
+ return array_key_exists($field, $headers);
+ }
+
+ /**
+ * Returns the Curl headers as an associated array
+ *
+ * @return array associated header array
+ */
+ public function getHeaderArray()
+ {
+ if (!empty($this->header_fields)) {
+ return $this->header_fields;
+ }
+
+ $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));
+ $this->header_fields[$headerfield] = $headerdata;
+ }
+
+ return $this->header_fields;