]> git.mxchange.org Git - friendica.git/blob - src/Util/HTTPHeaders.php
port hubzillas OpenWebAuth - remote authentification
[friendica.git] / src / Util / HTTPHeaders.php
1 <?php
2 /**
3  * @file src/Util/HTTPHeaders.php
4  */
5 namespace Friendica\Util;
6
7 class HTTPHeaders
8 {
9         private $in_progress = [];
10         private $parsed = [];
11
12         function __construct($headers)
13         {
14                 $lines = explode("\n", str_replace("\r", '', $headers));
15
16                 if ($lines) {
17                         foreach ($lines as $line) {
18                                 if (preg_match('/^\s+/', $line, $matches) && trim($line)) {
19                                         if ($this->in_progress['k']) {
20                                                 $this->in_progress['v'] .= ' ' . ltrim($line);
21                                                 continue;
22                                         }
23                                 } else {
24                                         if ($this->in_progress['k']) {
25                                                 $this->parsed[] = [$this->in_progress['k'] => $this->in_progress['v']];
26                                                 $this->in_progress = [];
27                                         }
28
29                                         $this->in_progress['k'] = strtolower(substr($line, 0, strpos($line, ':')));
30                                         $this->in_progress['v'] = ltrim(substr($line, strpos($line, ':') + 1));
31                                 }
32                         }
33
34                         if ($this->in_progress['k']) {
35                                 $this->parsed[] = [$this->in_progress['k'] => $this->in_progress['v']];
36                                 $this->in_progress = [];
37                         }
38                 }
39         }
40
41         function fetch()
42         {
43                 return $this->parsed;
44         }
45
46         function fetcharr()
47         {
48                 $ret = [];
49
50                 if ($this->parsed) {
51                         foreach ($this->parsed as $x) {
52                                 foreach ($x as $y => $z) {
53                                         $ret[$y] = $z;
54                                 }
55                         }
56                 }
57                 return $ret;
58         }
59 }