Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1 KiB

  1. <?php
  2. /**
  3. * @file src/Util/HTTPHeaders.php
  4. */
  5. namespace Friendica\Util;
  6. /**
  7. * Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/Zotlabs/Web/HTTPHeaders.php
  8. */
  9. class HTTPHeaders
  10. {
  11. private $in_progress = [];
  12. private $parsed = [];
  13. function __construct($headers)
  14. {
  15. $lines = explode("\n", str_replace("\r", '', $headers));
  16. if ($lines) {
  17. foreach ($lines as $line) {
  18. if (preg_match('/^\s+/', $line, $matches) && trim($line)) {
  19. if (!empty($this->in_progress['k'])) {
  20. $this->in_progress['v'] .= ' ' . ltrim($line);
  21. continue;
  22. }
  23. } else {
  24. if (!empty($this->in_progress['k'])) {
  25. $this->parsed[] = [$this->in_progress['k'] => $this->in_progress['v']];
  26. $this->in_progress = [];
  27. }
  28. $this->in_progress['k'] = strtolower(substr($line, 0, strpos($line, ':')));
  29. $this->in_progress['v'] = ltrim(substr($line, strpos($line, ':') + 1));
  30. }
  31. }
  32. if (!empty($this->in_progress['k'])) {
  33. $this->parsed[$this->in_progress['k']] = $this->in_progress['v'];
  34. $this->in_progress = [];
  35. }
  36. }
  37. }
  38. function fetch()
  39. {
  40. return $this->parsed;
  41. }
  42. }