Parses a Cache-Control HTTP header.

@param string $header The value of the Cache-Control HTTP header

@return array An array representing the attribute values
765756
protected function parseCacheControl($header)
    {
        $cacheControl = [];
        \preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
        foreach ($matches as $match) {
            $cacheControl[\strtolower($match[1])] = $match[3] ?? ($match[2] ?? true);
        }

        return $cacheControl;
    }
1043014
private function parseHttp($header) {
        list($version,$code,$message) = explode(" ", $header);
        
        $versionParts = explode("/",$version);
        $this->version = end($versionParts);
        $this->code = $code;
        $this->message = $message;
    }
972859
private static function parseAcceptHeader($header): array
    {
        // empty array
        $accept = [];

        // check empty
        if (!$header || $header === '') {
            return $accept;
        }

        // make array from header
        $values = explode(',', $header);
        $values = array_map('trim', $values);

        foreach ($values as $a) {
            // the default quality is 1.
            $q = 1;
            // check if there is a different quality
            if (strpos($a, ';q=') || strpos($a, '; q=')) {
                // divide "mime/type;q=X" into two parts: "mime/type" i "X"
                [$a, $q] = preg_split('/;([ ]?)q=/', $a);
            }
            // remove other extension
            if (strpos($a, ';')) {
                $a = substr($a, 0, strpos($a, ';'));
            }

            // mime-type $a is accepted with the quality $q
            // WARNING: $q == 0 means, that isn’t supported!
            $accept[$a] = (float)$q;
        }
        arsort($accept);
        return $accept;
    }
723087
protected function _extractHttpCode($header) {
		preg_match(
			'#^HTTP/[0-9\.]+\s(?P<code>[0-9]+)#i',
			$header,
			$matches
		);

		return isset($matches['code'])
			? $matches['code']
			: $this->_defaultCode;
	}
75788
public function getHeader($header)
    {
        return isset($this->getHeaders()[$header]) ? $this->getHeaders()[$header] : null;
    }
475491
private function parseHeader($header)
    {
        if (!\preg_match_all('/(?:[^,"]*+(?:"[^"]*+")?)+[^,"]*+/', $header, $matches)) {
            throw new InvalidArgumentException('Failed to parse accept header: "' . $header . '"');
        }

        return \array_values(\array_filter(\array_map('\trim', $matches[0])));
    }
335986
public function setHttpHeader($header)
    {
        $headers = $this->getHttpHeaders();
        $headers[] = $header;
        $this->setHttpHeaders($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;
    }
478498
public function header($header) {
        foreach($this->_headers as $k => $v) {
            if (!strcasecmp($k, $header)) {
                return $v;
            }
        }
        
        return null;
    }
869567
public static function parseHeaders($headers)
    {
        $httpCode  = null;
        $result    = null;
        $processed = [];

        foreach (explode(HttpHelper::EOL, $headers) as $lineNumber => $line) {
            if ($lineNumber === 0) {
                // first line of result is special
                if (preg_match("/^HTTP\/\d+\.\d+\s+(\d+)/", $line, $matches)) {
                    $httpCode = (int) $matches[1];
                }
                $result = $line;
            } else {
                // other lines contain key:value-like headers
                // the following is a performance optimization to get rid of
                // the two trims (which are expensive as they are executed over and over) 
                if (strpos($line, ': ') !== false) {
                    list($key, $value) = explode(': ', $line, 2);
                } else {
                    list($key, $value) = explode(':', $line, 2);
                }
                $processed[strtolower($key)] = $value;
            }
        }

        return [$httpCode, $result, $processed];
    }
1152653
private function parseHttpHeaders($headers) {
    $result = [];
    foreach ($headers as $header) {
      $values = explode(':', $header, 2);
      if (count($values) === 2) {
        list($key, $value) = $values;
        $key = trim($key);
        $value = trim($value);
        // Checking with real cURL it only sends a header if the key & the value
        // are set.
        if ($key && $value) {
          $result[$key] = $value;
        }
      }
    }
    return $result;
  }
745317
private function setHeader($header)
    {
        preg_match("'\[(.*?)\] 'si", $header, $match);
        if (!isset($match[1])) {
            throw new Exception('Unable to read datetime from header.');
        }
        $this->setDatetime($match[1]);

        $header = $this->cleanHeader($header);

        if (preg_match('/^[a-z]+.[A-Z]+:/', $header, $out)) {
            $this->setEnv($out[0]);
            $header = trim(str_replace($out[0], '', $header));
        }

        $this->header = $header;

        return $this;
    }
45598
public function parseHeaders($src)
    {
        $headers = array();

        foreach ($src as $i) {
            $row = explode(':', $i, 2);

            // header with no key/value - HTTP response, get code and status
            if(!isset($row[1])){

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

                continue;
            }

            $key = trim($row[0]);
            $val = trim($row[1]);
            $headers[$key] = $val;
        }
        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;
    }
201140
private function getHeaderIp(string $header)
    {
        foreach (array_reverse(array_map('trim', explode(',', $header))) as $ip) {
            if (self::isValid($ip) && !$this->isInProxiedIps($ip)) {
                return $ip;
            }
        }
    }
595609
public function splitHttpAcceptHeader($header)
    {
        $values = [];
        foreach (array_filter(explode(',', $header)) as $value) {
            // Cut off any q-value that might come after a semi-colon
            if ($pos = strpos($value, ';')) {
                $q = (float) trim(substr($value, strpos($value, '=') + 1));
                $value = substr($value, 0, $pos);
            } else {
                $q = 1;
            }

            if (0 < $q) {
                $values[trim($value)] = $q;
            }
        }

        arsort($values);

        return array_keys($values);
    }
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;
    }