3 * @file src/Util/HTTPHeaders.php
5 namespace Friendica\Util;
8 * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/Zotlabs/Web/HTTPHeaders.php
12 private $in_progress = [];
15 function __construct($headers)
17 $lines = explode("\n", str_replace("\r", '', $headers));
20 foreach ($lines as $line) {
21 if (preg_match('/^\s+/', $line, $matches) && trim($line)) {
22 if (!empty($this->in_progress['k'])) {
23 $this->in_progress['v'] .= ' ' . ltrim($line);
27 if (!empty($this->in_progress['k'])) {
28 $this->parsed[] = [$this->in_progress['k'] => $this->in_progress['v']];
29 $this->in_progress = [];
32 $this->in_progress['k'] = strtolower(substr($line, 0, strpos($line, ':')));
33 $this->in_progress['v'] = ltrim(substr($line, strpos($line, ':') + 1));
37 if (!empty($this->in_progress['k'])) {
38 $this->parsed[$this->in_progress['k']] = $this->in_progress['v'];
39 $this->in_progress = [];