Parses the raw headers and sets as an array.

@param string The raw headers from the response.

@return array
967072
protected function getHeaders(string $raw_headers) {
        // Normalize line breaks
        $raw_headers = str_replace("\r\n", "\n", $raw_headers);

        // There will be multiple headers if a 301 was followed
        // or a proxy was followed, etc
        $header_collection = explode("\n\n", trim($raw_headers));
        // We just want the last response (at the end)
        $raw_header = array_pop($header_collection);

        $header_components = explode("\n", $raw_header);
        $result = array();
        $http_status = 0;
        foreach ($header_components as $line) {
            if (strpos($line, ': ') === false) {
                $http_status = $this->getHttpStatus($line);
            } else {
                list($key, $value) = explode(': ', $line, 2);
                $result[$key] = $value;
            }
        }

        return array($http_status, $result);
    }
93737
public function parseHeader()
    {
        //$header = explode("\r\n", rtrim($this->response['headerRaw'], "\r\n"));
        
        $rawHeaders = rtrim($this->response['headerRaw'], "\r\n");
        # Handle multiple responses e.g. with redirections (proxies too)
        $headerGroups = explode("\r\n\r\n", $rawHeaders);
        # We're only interested in the last one
        $header = explode("\r\n", end($headerGroups));

        $output = array();

        if ('HTTP' === substr($header[0], 0, 4)) {
            list($output['version'], $output['status']) = explode(' ', $header[0]);
            unset($header[0]);
        }

        foreach ($header as $entry) {
            $pos = strpos($entry, ':');
            $output[trim(substr($entry, 0, $pos))] = trim(substr($entry, $pos + 1));
        }

        $this->response['header'] = $output;
        return $this;
    }
692563
protected function _parseResponseHeaders($headers)
    {
        $headers = str_replace("\r", "", $headers);
        $headers = explode("\n", $headers);
        $parsed  = array();

        foreach($headers as $header)
        {
            $field_end = strpos($header, ':');

            if($field_end === FALSE)
            {
                /* Cover the case where we're at the first header, the HTTP
                 *  status header
                 */
                $field = 'status';
                $value = $header;
            }
            else
            {
                $field = substr($header, 0, $field_end);
                $value = substr($header, $field_end + 1);
            }

            $parsed[$field] = $value;
        }

        return $parsed;
    }
157026
public static function parseHeaders(string $headers): array
    {
        $res = [];

        foreach (explode("\r\n", $headers) as $line) {
            $line = trim($line);
            if (!$line) {
                continue;
            }

            $line = explode(': ', $line);
            if (count($line) !== 2) {
                continue;
            }

            $res[strtolower($line[0])] = $line[1];
        }

        return $res;
    }
288211
private function parseHeader($header)
    {
        $res = preg_match_all('/(?:[^,"]*+(?:"[^"]*+")?)+[^,"]*+/', $header, $matches);

        if (!$res) {
            throw new InvalidHeader(sprintf('Failed to parse accept header: "%s"', $header));
        }

        return array_values(array_filter(array_map('trim', $matches[0])));
    }
1320725
public static function parse_headers(string $headers): array
    {
        $final_headers = array();
        $list = explode("\n", trim($headers));

        $http = array_shift($list);

        foreach ($list as $header) {
            $parts = explode(':', $header, 2);
            $final_headers[trim($parts[0])] = isset($parts[1]) ? trim($parts[1]) : '';
        }

        return $final_headers;
    }
1195562
public static function parseResponse($response)
    {
        $response = str_replace("HTTP/1.1 100 Continue\r\n\r\n", '', $response);
            
        list($rawHeader, $rawBody) = explode("\r\n\r\n", $response, 2);

        // Parse headers and status.
        $headers = self::parseRawHeader($rawHeader);
        $status = array_shift($headers);

        return array($status, $headers, $rawBody);
    }
574948
public function parseHeaders($src)
    {
        $headers = array();

        $codeMatched = false;
        
        // curl request header
        if (!is_array($src)) {
            $src = explode("\n",$src);
        }
                
        foreach ($src as $i) {
            $row = explode(':', $i, 2);
            
            // header with no key/value - HTTP response, get code and status
            if(!isset($row[1])){
                $headers[] = $row[0];

                $matches = array();
                if(!$codeMatched && preg_match('#HTTP/1.[0-1] ([0-9]{3})(.*)#si', $row[0], $matches)){
                    $headers['Code'] = $matches[1];
                    $headers['Status'] = trim($matches[2]);
                    $codeMatched = true;
                }

                continue;
            }

            $key = trim($row[0]);
            $val = trim($row[1]);
            $headers[$key] = $val;
        }
        return $headers;
    }
976209
private function parseForecastResponseHeaders($headers)
    {
        $responseHeaders = [
            'cache' => [
                'maxAge' => null,
                'expires' => null
            ],
            'responseTime' => null,
            'apiCalls' => null
        ];
        foreach ($headers as $header) {
            switch (true) {
                case (substr($header, 0, 14) === 'Cache-Control:'):
                    $responseHeaders['cache']['maxAge'] = trim(substr($header, strrpos($header, '=') + 1));
                    break;
                case (substr($header, 0, 8) === 'Expires:'):
                    $responseHeaders['cache']['expires'] = trim(substr($header, 8));
                    break;
                case (substr($header, 0, 21) === 'X-Forecast-API-Calls:'):
                    $responseHeaders['apiCalls'] = trim(substr($header, 21));
                    break;
                case (substr($header, 0, 16) === 'X-Response-Time:'):
                    $responseHeaders['responseTime'] = (int)trim(substr($header, 16));
                    break;
                default:
                    break;
            }
        }
        return $responseHeaders;
    }
236518
protected function getHeadersAsArray($rawHeaders)
    {
        $headers = [];

        foreach (explode("\r\n", (string) $rawHeaders) as $header) {
            if (false !== strpos($header, ':')) {
                list($name, $headerStr) = explode(':', $header, 2);
                $headers[trim($name)] = trim($headerStr);
            }
        }

        return $headers;
    }
916221
public static function parseCookieHeader($header)
    {
        $cookies = array();
        $header = rtrim($header, "\r\n");
        $headerPieces = preg_split('@\s*[;,]\s*@', $header);
        foreach ($headerPieces as $c) {
            $cParts = explode('=', $c, 2);
            if (count($cParts) === 2) {
                $key = urldecode($cParts[0]);
                $value = urldecode($cParts[1]);
                if (!isset($cookies[$key])) {
                    $cookies[$key] = $value;
                }
            }
        }

        return $cookies;
    }
630318
public function parse($raw)
    {
        $lines = explode("\n", $raw);

        // Status Line
        preg_match('/HTTP\/(\d\.\d) (\d\d\d) (.*)/', $lines[0], $statusLine);
        $response = (new Response())
            ->withProtocolVersion($statusLine[1])
            ->withStatus($statusLine[2], $statusLine[3]);
        unset($lines[0]);

        // Headers
        foreach ($lines as $i => $line) {
            if ('' == trim($line)) {
                unset($lines[$i]);
                break;
            }
            $header   = explode(': ', $line);
            $response = $response->withHeader($header[0], $header[1]);
            unset($lines[$i]);
        }

        // Body
        $stream = new Stream(fopen('php://memory', 'rw+'));
        $stream->write(implode("\n", $lines));
        $stream->rewind();
        $response = $response->withBody($stream);

        return $response;
    }
1326951
function parse(headers) {
    var output = {}, i, p, k, v;
    headers = headers || '';
    headers = headers.replace('\r', '');
    headers = headers.split('\n');
    for(i = 0;i < headers.length;i++) {
      p = headers[i].indexOf(':');
      k = headers[i].substr(0, p);
      v = headers[i].substr(p + 1);
      if(k && v) {
        k = k.replace(/^\s+/, '').replace(/\s+$/, '');
        v = v.replace(/^\s+/, '').replace(/\s+$/, '');
        output[k.toLowerCase()] = v;
      }
    }
    return output;
  }
1312933
protected function parseHeaders($headersStr)
    {
        $headersArr  = array();
        $headersHlpr = explode("\r\n", $headersStr);

        foreach ($headersHlpr as $header) {
            $pos = strpos($header, ':');
            if ($pos === false) {
                $headersArr[] = trim($header);
            } else {
                $headersArr[trim(substr($header, 0, $pos))] = trim(substr($header, ($pos + 1)));
            }
        }

        return $headersArr;
    }
476750
protected function parseHeaders($rawHeaders)
    {
        $headers = array();

        $lines = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $rawHeaders));
        foreach ($lines as $header) {
            if (preg_match('/([^:]+): (.+)/m', $header, $match)) {
                if (!isset($headers[$match[1]])) {
                    $headers[$match[1]] = trim($match[2]);
                } elseif (is_array($headers[$match[1]])) {
                    $headers[$match[1]][] = trim($match[2]);
                } else {
                    $headers[$match[1]] = array($headers[$match[1]], trim($match[2]));
                }
            }
        }

        return $headers;
    }
136837
public function parseReturnHeaders($headers)
    {
        $head = [];
        foreach ($headers as $k => $v) {
            $t = explode(':', $v, 2);
            if (isset($t[1])) {
                $head[trim($t[0])] = trim($t[1]);
            } else {
                $head[] = $v;
                if (preg_match("#HTTP/[0-9\.]+\s+([0-9]+)#", $v, $out)) {
                    $head['reponse_code'] = intval($out[1]);
                }
            }
        }
        $this->debug->debug(__FUNCTION__, 'Response Header: ', $head);

        return $head;
    }
319438
public static function parse($raw)
    {
        self::$parsed = [];
        list($headings, $data) = self::parseRawData($raw);

        if (!is_array($headings)) {
            // @codeCoverageIgnoreStart
            return self::$parsed;
            // @codeCoverageIgnoreEnd
        }

        foreach ($headings as $heading) {
            for ($i = 0, $j = count($heading); $i < $j; $i++) {
                self::populateEntries($heading, $data, $i);
            }
        };

        unset($headings, $data);

        return array_reverse(self::$parsed);
    }