Convert headers from key/value pair to a index based array.

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

        return $result;
    }
1291631
protected function setHeaders(array $headers)
    {
        foreach ($headers as $header) {

            if (isset($header['name']) && isset($header['value'])) {
                $this->headers[$header['name']] = $header['value'];
            }
        }

        return $this;
    }
245463
private function parseHeaders(array $headers)
    {

        // Set the raw headers as we got from the constructor.
        $this->raw_headers = $headers;

        // flatten the headers array so that values are not arrays themselves
        // but rather simple key value pairs.
        $headers = array_map(function ($value) {

            if (! is_array($value))
                return $value;

            return implode(';', $value);
        }, $headers);

        // Set the parsed headers.
        $this->headers = $headers;

        // Check for some header values that might be interesting
        // such as the current error limit and number of pages
        // available.
        $this->hasHeader('X-Esi-Error-Limit-Remain') ?
            $this->error_limit = (int) $this->getHeader('X-Esi-Error-Limit-Remain') : null;

        $this->hasHeader('X-Pages') ? $this->pages = (int) $this->getHeader('X-Pages') : null;
    }
54001
protected function encodeHeaders(array $headers): string
    {
        $data = '';

        foreach ($headers as $name => $values) {
            foreach ($values as $value) {
                $data .= sprintf("%s: %s\r\n", $name, $this->encodeHeader($value));
            }
        }

        return $data;
    }
980499
public function addHeaders(array $headers)
    {

        foreach ($headers as $key => $value) {
            $header = NULL;
            //Handle Array of String based Headers
            if (is_numeric($key) && strpos($value,":") !== FALSE) {
                $arr = explode(":",$value,2);
                if (count($arr)==2){
                    $header = $arr[0];
                    $value = trim($arr[1]);
                }
            } else {
                $header = $key;
            }
            if ($header !== NULL){
                $this->addHeader($header, $value);
            }
        }
        return $this;
    }
1228927
protected function response_headers_array(array $response_headers):array {
		$headers = [];

		foreach($response_headers as $key => $value){
			$headers[$key] = $value;
		}

		return $headers;
	}
953972
public static function decode(array $headers = []): array
    {
        $encodedHeaders = [];
        $encodedProperties = [];
        $prefixLength = strlen(self::PROPERTY_PREFIX);

        // separate headers/properties
        foreach ($headers as $key => $value) {
            if (0 === strpos($key, self::PROPERTY_PREFIX)) {
                $encodedProperties[substr($key, $prefixLength)] = $value;
            } else {
                $encodedHeaders[$key] = $value;
            }
        }

        $decodedHeaders = self::doDecode($encodedHeaders);
        $decodedProperties = self::doDecode($encodedProperties);

        return [$decodedHeaders, $decodedProperties];
    }
240709
private function parseHeaders($headers): array {
        if (is_string($headers)) {
            $headers = explode("\r\n", $headers);
        }

        if (empty($headers)) {
            return [];
        }

        $result = [];
        foreach ($headers as $key => $line) {
            if (is_numeric($key)) {
                if (strpos($line, 'HTTP/') === 0) {
                    // Strip the status line and restart.
                    $result = [];
                    continue;
                } elseif (strstr($line, ': ')) {
                    list($key, $line) = explode(': ', $line);
                } else {
                    continue;
                }
            }
            if (is_array($line)) {
                $result[$key] = array_merge($result[$key] ?? [], $line);
            } else {
                $result[$key][] = $line;
            }
        }

        return $result;
    }
932805
private function prettifyHeaders(array $headers)
    {
        return array_reduce(
            array_filter($headers),
            function ($result, $header) {

                if (false === strpos($header, ':')) {
                    $result['Status'] = trim($header);

                    return $result;
                }

                list($key, $value) = explode(':', $header, 2);
                $result[trim($key)] = trim($value);

                return $result;
            },
            []
        );
    }
8127
public static function parse($headers) {
       $fields = explode("\r\n", preg_replace('/\x0D\x0A[\x09\x20]+/', ' ', $headers));

       if(empty($fields)) return [];

       return array_reduce($fields, function($carry, $field) {
           $match = [];
           if (!preg_match('/([^:]+): (.+)/m', $field, $match)) return $carry;

           $match[1] = preg_replace_callback('/(?<=^|[\x09\x20\x2D])./',function($matches) {
               return strtoupper($matches[0]);
           }, strtolower(trim($match[1])));

           if (!isset($carry[$match[1]])) {
               $carry[$match[1]] = trim($match[2]);
               return $carry;
           }
           
           if (is_array($carry[$match[1]])) {
               $carry[$match[1]][] = trim($match[2]);      
               return $carry;
           }
           
           $carry[$match[1]] = [$carry[$match[1]], trim($match[2])];

           return $carry;
       }, []);
    }
964756
public function addHeaders(array $headers = [])
    {
        $this->headers = [];
        if($headers != []) {
            foreach ($headers as $header) {
                $this->headers[] = $header;
            }
        }
        return $this;
    }
748927
protected function getHeaders($params)
    {
        $headers = array();
        
        foreach ($params as $name => $value) {
            if (substr($name, 0, 5) === 'HTTP_') {
                $key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
                $headers[$key] = $value;
            }
        }
        
        return $headers;
    }
229644
protected function encodeHeaders($headers = [])
    {
        $data = '';

        foreach ($headers as $name=>$values)
        {
            $temp = [];
            $data .= $name . ": ";
            $values = (array) $values;

            foreach ($values as $value)
            {
                $temp[] = $this->encodeHeader($value);
            }

            $data .= implode(", ", $temp);
            $data .= "\r\n";
        }

        return $data;
    }
1075431
protected function normalizeHeaders(array $headers) : array
    {
        $returnHeaders = [];
        foreach ($headers as $key => $header) {
            $returnHeaders[$key] = $header[0] ?? $header;
        }

        return $returnHeaders;
    }
1116612
private function buildCanonicalHeaders($headers)
    {
        $sortMap = [];
        foreach ($headers as $headerKey => $headerValue) {
            $key = strtolower($headerKey);
            if (strpos($key, "x-acs-") === 0) {
                $sortMap[$key] = $headerValue;
            }
        }
        ksort($sortMap);
        $headerString = "";
        foreach ($sortMap as $sortMapKey => $sortMapValue) {
            $headerString = $headerString . $sortMapKey . ":" . $sortMapValue . self::$headerSeparator;
        }
        return $headerString;
    }
1353186
private function normalizeHeaders(array $headers)
    {
        $ignoreHeaders = $this->ignoreHeaders;

        foreach ($ignoreHeaders as $ignoreHeader) {
            $headers = array_filter($headers, function($header) use ($ignoreHeader) {
                return stripos($header, $ignoreHeader.':') !== 0;
            });
        }

        return $headers;
    }
1047284
private function getHeaders(array $headers)
    {
        $str = '';
        foreach ($headers as $key => $value) {
            $str .= sprintf("%s: %s\r\n", $key, $value);
        }

        return $str;
    }