Parses headers to an array
@param $headers
4214
private function parseHeaders($headers)
    {
        $headers_temp = array();

        $requests = explode("\r\n\r\n", $headers);
        // follow eventual redirections
        for ($index = 0; $index < count($requests) - 1; $index++) {

            foreach (explode("\r\n", $requests[$index]) as $i => $line) {
                if ($i === 0)
                    continue;
                list($key, $value) = explode(': ', $line);
                $headers_temp[$index][$key] = $value;
            }
        }
        // gets always the latest response
        $this->headers = end($headers_temp) !== false ? end($headers_temp) : [];
    }
1183336
protected function setResponseHeaders(array $headers)
    {
        // reset headers
        $this->headers = [];

        // set response status header
        $this->headers[] = 'HTTP/1.1 ' . $this->getStatusCode() . ' ' . $this->getStatusText();

        // set content type header
        $this->headers['Content-Type'] = 'application/json';

        // set user supplied headers
        foreach ($headers as $key => $value) {
            $this->headers[$key] = $value;
        }
    }
70985
public function parseHeaders(array $headers)
    {
        foreach ($headers as $key => $value) {
            if (strpos($key, 'HTTP_') !== false) {
                $newKey                 = str_replace(['http_', '_'], ['', '-'],
                    mb_strtolower($key));
                $this->headers[$newKey] = $value;
            }
        }
        return $this->headers;
    }
911010
protected function parseHeaders($headers)
    {
        $headers = str_replace("\r\n", "\n", $headers);
        $headers = explode("\n", $headers);

        array_shift($headers);

        $parsedHeaders = [];
        foreach ($headers as $header) {
            list($key, $value) = explode(':', $header, 2);

            $parsedHeaders[$key] = trim($value);
        }

        return $parsedHeaders;
    }
113232
private function parse($headers)
    {
        foreach (preg_split('/\r\n|\r|\n/', $headers) as $i => $line) {
            if ($i === 0) {
                $this->headers['http_code'] = $line;
            } else {
                list($key, $value) = explode(': ', $line);

                if ($key === 'Set-Cookie') {
                    list($textCookie) = explode(';', $value);
                    list($cookieKey, $cookieValue) = explode('=', $textCookie);

                    $this->cookies[$cookieKey] = $cookieValue;
                } else {
                    $this->headers[$key] = $value;
                }
            }
        }
    }
590948
protected function prepareHeaders(array $headers)
    {
        $preparedHeaders = [];

        foreach ($headers as $strName => $varValue) {
            $preparedHeaders[] = $strName.': '.$varValue;
        }

        return $preparedHeaders;
    }
1374112
protected function getHeadersAsString(array $headers)
    {
        $rawHeaders = [];

        foreach ($headers as $name => $header) {
            $rawHeaders[] = sprintf('%s: %s', trim($name), trim($header));
        }

        $rawHeaders = implode("\r\n", $rawHeaders);

        return $rawHeaders;
    }
649552
public function setCustomHeaders(array $headers)
    {
        foreach ($headers as $k => &$v) {
            if (strpos($v, ':') === false) {
                $v = $k.': '.$v;
            }
        }
        $this->headers = $headers;
    }
166653
function parseHeaders(headers) {
  var parsed = {}, key, val, i;

  if (!headers) return parsed;

  forEach(headers.split('\n'), function(line) {
    i = line.indexOf(':');
    key = lowercase(trim(line.substr(0, i)));
    val = trim(line.substr(i + 1));

    if (key) {
      if (parsed[key]) {
        parsed[key] += ', ' + val;
      } else {
        parsed[key] = val;
      }
    }
  });

  return parsed;
}
524071
protected function prepareHeaders(array $rawHeaders)
    {
        $headers = array();
        
        foreach ($rawHeaders as $rawHeader) {
            if (strpos($rawHeader, ':')) {
                $data = explode(':', $rawHeader);
                $headers[$data[0]][] = trim($data[1]);
            }            
        }
        
        return $headers;
    }
597773
public static function parse($headers)
    {
        if (is_string($headers)) {
            $headers = explode("\r\n\r\n", trim($headers));

            return explode("\r\n", end($headers));
        }

        $parsedHeaders = [];

        foreach ($headers as $name => $value) {
            $value = HeadersNormalizer::normalizeHeaderValue($value);

            if (is_int($name)) {
                if (strpos($value, 'HTTP/') === 0) {
                    $parsedHeaders = [$value];
                } else {
                    $parsedHeaders[] = $value;
                }
            } else {
                $parsedHeaders[] = $name.': '.$value;
            }
        }

        return $parsedHeaders;
    }
272702
protected function setHeaders(array $headers)
    {
        $this->headerNames = $this->headerValues = [];

        foreach ($headers as $name => $value) {
            if (!is_array($value)) {
                $value = [$value];
            }

            if (in_array(false, array_map('is_string', $value))) {
                throw new InvalidArgumentException('Header value must be string or array of string.');
            }

            $lowerName = strtolower($name);
            $this->headerNames[$lowerName] = $name;
            $this->headerValues[$lowerName] = $value;
        }
    }
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;
    }
1121484
protected function addHeaders(array $headers)
    {
        foreach ($headers as $key => $val) {
            $normalized = strtolower($key);
            $this->headers[$key] = (array)$val;
            $this->headerNames[$normalized] = $key;
        }
    }
756253
protected function parseIncomingCookies($headers)
    {
        $this->incomingTrackerCookies = array();
        
        if (!empty($headers)) {
            $headerName = 'set-cookie:';
            $headerNameLength = strlen($headerName);
            
            foreach($headers as $header) {
                if (strpos(strtolower($header), $headerName) !== 0) {
                    continue;
                }
                $cookies = trim(substr($header, $headerNameLength));
                $posEnd = strpos($cookies, ';');
                if ($posEnd !== false) {
                    $cookies = substr($cookies, 0, $posEnd);
                }
                parse_str($cookies, $this->incomingTrackerCookies);
            }
        }   
    }
612501
private function normalizeHeaders($headers)
    {
        if (is_array($headers)) {
            $headers = new Headers($headers);
        } elseif (!($headers instanceof Headers)) {
            throw new InvalidArgumentException(
                'Headers must be an array or instance of Headers'
            );
        }

        return $headers;
    }
1261704
protected function withHeaders(array $headers)
    {
        $clean = [];

        foreach ($headers as $key => $value) {
            if (! Str::startsWith($key, ['HTTP_', 'CONTENT_'])) {
                $key = 'HTTP_' . $key;
            }

            $clean[$key] = $value;
        }

        $this->headers = array_merge($this->headers, $clean);

        return $this;
    }