Backwards compatibility helper for getting flattened headers.

Previously CakePHP would store headers as a simple dictionary, now that
we're supporting PSR7, the internal storage has each header as an array.

@return array
505895
protected function getSimpleHeaders()
    {
        $out = [];
        foreach ($this->headers as $key => $values) {
            $header = $this->headerNames[strtolower($key)];
            if (count($values) === 1) {
                $values = $values[0];
            }
            $out[$header] = $values;
        }

        return $out;
    }
1314226
public function getHeaders()
    {
        $headers = array();
        if (isset($_SERVER)) {
            foreach ($_SERVER as $key => $val) {
                if (substr($key, 0, 5) == 'HTTP_') {
                    // convert HTTP_CONTENT_TYPE to Content-Type, HTTP_HOST to Host, etc.
                    $name = strtolower(substr($key, 5));
                    $name = str_replace(' ', '-', ucwords(str_replace('_', ' ', $name)));
                    $headers[$name] = $val;
                }
            }
        }
        if (count($headers) > 0) {
            return $headers;
        } else {
            return null;
        }
    }
291680
public function getResponseHeaders() {
        $requestHeaders = [];

        if ($this->headers instanceof \ArrayAccess) {
            while ($this->headers->valid()) {
                $requestHeaders[$this->headers->key()] = $this->headers->current();
                $this->headers->next();
            }
        }

        return $requestHeaders;
    }
356794
public function getHeaders()
    {
        $headers = array();
        $matches = array();
        if (preg_match_all('/([\w-]+): (.*)/', $this->lastHeader, $matches)) {
            for ($i = count($matches[0]) - 1; $i >= 0; $i--) {
                $headers[strtolower($matches[1][$i])] = $matches[2][$i];
            }
        }
        return $headers;
    }
256582
public function getHeaders(): array
    {
        if ($this->headers === null && $this->headersText !== null) {
            $this->headers = [];

            foreach (explode("\n", $this->headersText) as $line) {
                $pos = strpos($line, ':');

                if ($pos === false) {
                    // this is one-line header
                    $this->headers[$line] = null;
                } else {
                    $name = substr($line, 0, $pos);
                    $value = substr($line, $pos + 1);
                    $this->headers[$name] = trim($value);
                }
            }
        }

        return $this->headers ?? [];
    }
954672
public function getHeaders()
	{
		// Define a headers array
		$headers = [];

		foreach($this->items as $key => $value)
		{
			// Does our server attribute have our header prefix ?
			if(strpos($key, $this->http_header_prefix) === 0)
			{
				$key = substr($key, strlen($this->http_header_prefix));
			}
			else if(! in_array($key, $this->http_nonprefixed_headers))
			{
				continue;
			}

			$key = HeaderCollection::normalizeKey($key);

			// Add our server attribute to our header array
			$headers[$key] = $value;
		}

		return $headers;
	}
72050
private static function normalizeHeaders(array $headers): array
    {
        $normalizedHeaders = [];

        foreach ($headers as $name => $values) {
            if (\is_int($name)) {
                [$name, $values] = explode(':', $values, 2);
                $values = [ltrim($values)];
            } elseif (!\is_iterable($values)) {
                $values = (array) $values;
            }

            $normalizedHeaders[$name = strtolower($name)] = [];

            foreach ($values as $value) {
                $normalizedHeaders[$name][] = $value;
            }
        }

        return $normalizedHeaders;
    }
598994
public function getRawHeaders()
    {
        $headers = [];

        foreach ($this->headers as $key => $value) {
            $headers[] = $key . ': ' . $value;
        }

        return $headers;
    }
765792
private function convertHeaders(array $headers)
    {
        $result = [];
        foreach ($headers as $key => $value) {
            $result[] = $key . ': ' . $value;
        }

        return $result;
    }
1177699
public function getHeaders() {
		$headers = array();
		foreach ($this->headers as $name => $values) {
			foreach ($values as $value) {
				$headers[] = strtolower($name) . ': ' . $value;
			}
		}
		$headers[] = self::HEADER_KEY_CONTENT_LENGTH . ': ' . strlen($this->getBody());
		return $headers;
	}
1064099
public function all(): array
    {
        $result = [];
        foreach ($this->headers as $header) {
            $result[$header->getName()] = $header->getValuesAsArray();
        }

        return $result;
    }
88239
protected function getHttpHeaders()
    {
        $headers = [];
        if (null !== $this->_maxage) {
            $headers['Cache-Control'] = 'max-age=' . $this->_maxage;
        }
        if ($this->_gzipped) {
            $headers['Content-Encoding'] = 'gzip';
        }

        return $headers;
    }
20662
public final function headers(array $headers = null): array
    {
        return ($headers == null) ? $this->getHeaders() : $this->setHeaders($headers);
    }
357025
protected function getHeaderArray(string $headers): array
    {
        $headerArray  = [];
        $headersArray = explode("\r\n", trim($headers));
        foreach ($headersArray as $line => $header) {
            if ($line > 0) {
                $pair                    = explode(': ', $header);
                $headerArray[$pair[0]][] = $pair[1];
            } else {
                $headerArray['status'][] = $header;
            }
        }

        return $headerArray;
    }
182778
public function getHeaders()
    {
        $headers = $this->header;
        $headers[] = 'User-Agent: ' . $this->getUserAgent();
        $itemId = $this->indexQueueItem->getIndexQueueUid();
        $pageId = $this->indexQueueItem->getRecordPageId();

        $indexerRequestData = [
            'requestId' => $this->requestId,
            'item' => $itemId,
            'page' => $pageId,
            'actions' => implode(',', $this->actions),
            'hash' => md5(
                $itemId . '|' .
                $pageId . '|' .
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']
            )
        ];

        $indexerRequestData = array_merge($indexerRequestData, $this->parameters);
        $headers[] = 'X-Tx-Solr-Iq: ' . json_encode($indexerRequestData, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES);

        return $headers;
    }
928588
public function extractHeaders()
    {
        $headers = [];
        foreach (array_keys($this->cors) as $headerField) {
            $headerData = $this->request->getHeaderLine($headerField);
            if ($headerData !== null) {
                $headers[$headerField] = $headerData;
            }
        }

        return $headers;
    }
515055
protected function canonicalizeHeaders()
    {
        $canonical = array();
        $headers = array();
        if (isset($this->config['headers'])) {
            $headers = array_map('strtolower', array_keys($this->config['headers']));
            if (count($this->config['headers']) > 0) {
                $headers = array_combine(
                    $headers,
                    array_values($this->config['headers'])
                );
            }
        }

        foreach ($this->headers_to_sign as $key) {
            $key = strtolower($key);
            if (isset($headers[$key])) {
                if (is_array($headers[$key]) && count($headers[$key]) >= 1) {
                    $value = trim($headers[$key][0]);
                } elseif (is_array($headers[$key]) && count($headers[$key]) === 0) {
                    continue;
                } else {
                    $value = trim($headers[$key]);
                }

                if (!empty($value)) {
                    $canonical[$key] = preg_replace('/\s+/', ' ', $value);
                }
            }
        }

        ksort($canonical);
        $serialized_header = '';
        foreach ($canonical as $key => $value) {
            $serialized_header .= $key . ':' . $value . "\t";
        }

        return rtrim($serialized_header);
    }