parseAcceptHeader

@param string $header

@return array
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;
    }
607787
public static function parse($header)
    {
        if (strpos($header, '=') === false) {
            $header = '='.$header;
        }

        list($name, $header) = explode('=', $header, 2);

        if (strpos($header, ';') === false) {
            $value = $header;
            $header = null;
        } else {
            list($value, $header) = explode(';', $header, 2);
        }

        $attributes = [];
        foreach (array_map('trim', explode(';', $header)) as $pair) {
            if (empty($pair)) {
                continue;
            }

            if (strpos($pair, '=') === false) {
                $attributeName = $pair;
                $attributeValue = null;
            } else {
                list($attributeName, $attributeValue) = explode('=', $pair);
            }

            $attributes[trim($attributeName)] = $attributeValue ? trim($attributeValue) : true;
        }

        $name = trim($name);
        $value = trim($value);

        return [!empty($name) ? $name : null, !empty($value) ? $value : null, $attributes];
    }
143401
public static function parseHeader(string $header): array
    {
        $cookie = [];
        $kvs = explode('; ', $header);
        $nv = explode('=', array_shift($kvs));
        $cookie['name'] = $nv[0];
        //because of some stupid system could return Set-Cookie: foo=''; so we must replace it.
        $cookie['value'] = str_replace(['\'\'', '""'], '', $nv[1]);
        foreach ($kvs as $kv) {
            $kv = explode('=', $kv);
            $kv[0] = strtolower($kv[0]);
            if (isset($kv[1])) {
                $cookie[$kv[0]] = $kv[1];
            } else {
                $cookie[$kv[0]] = true;
            }
        }
        /**
         * If a response includes both an Expires header and a max-age directive,
         * the max-age directive overrides the Expires header!
         */
        if (isset($cookie['max-age'])) {
            $cookie['expires'] = time() + $cookie['max-age'];
        } else {
            if (isset($cookie['expires'])) {
                $cookie['expires'] = strtotime($cookie['expires']);
            }
        }

        return $cookie;
    }
1815
private static function parseAuthorizationHeader($header)
    {
        if (strpos($header, 'Digest') !== 0) {
            return false;
        }

        $needed_parts = ['nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1];
        $data = [];

        preg_match_all('@('.implode('|', array_keys($needed_parts)).')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', substr($header, 7), $matches, PREG_SET_ORDER);

        if ($matches) {
            foreach ($matches as $m) {
                $data[$m[1]] = $m[3] ? $m[3] : $m[4];
                unset($needed_parts[$m[1]]);
            }
        }

        return empty($needed_parts) ? $data : false;
    }
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;
    }
1335544
public function getHeader($header)
    {
        $response = $this->getResponse();

        return $response->hasHeader($header) ? $response->getHeader($header)[0] : null;
    }
317771
private function parseHeader($header)
    {
        //$this->logger->debug('Parsing request header');
        $header = explode("\n", $header); //Now it contains header lines
        $statusLine = explode(' ', trim($header[0]), 3); //Eg.: GET /file HTTP/1.1 will be parsed into [GET, /file, HTTP/1.1]
        if (!isset($statusLine[2]) || substr($statusLine[2], 0, 5) !== 'HTTP/') {
            throw new HttpException('Request is not HTTP complaint.', HttpCode::BAD_REQUEST, array(), true);
        }

        if (isset($statusLine[1][self::MAX_URI_LENGTH])) { //Much faster than using strlen(...) > MAX_URI_LENGTH
            throw new HttpException('URI should be equal or less than ' . self::MAX_URI_LENGTH . ' characters',
                HttpCode::REQUEST_URI_TOO_LONG);
        }

        $this->method = $statusLine[0];

        $fullUri = explode('?', $statusLine[1], 2); //URL + query string, eg. [/file, var1=test&var2=foo&bar=derp]
        $this->uri = $fullUri[0];

        if (isset($fullUri[1])) {
            $this->queryString = $fullUri[1];
        }

        $this->protocolVersion = substr($statusLine[2], 5); //Everything after HTTP/ is http version number
        if ($this->protocolVersion !== '1.1' && $this->protocolVersion !== '1.0') {
            throw new HttpException('Requested HTTP version is not supported', HttpCode::VERSION_NOT_SUPPORTED, array(),
                true);
        }

        unset($header[0]); //Status line
        $this->populateHeaders($header); //Everything left from header is actually http headers

        $this->isRequestCollected = true;
        //$this->logger->debug('Got HTTP headers, request is collected');
    }
75788
public function getHeader($header)
    {
        return isset($this->getHeaders()[$header]) ? $this->getHeaders()[$header] : null;
    }
374591
private static function parseAuthorizationHeader($header)
    {
        if (strpos($header, 'Basic') !== 0) {
            return false;
        }

        $header = explode(':', base64_decode(substr($header, 6)), 2);

        return [
            'username' => $header[0],
            'password' => isset($header[1]) ? $header[1] : null,
        ];
    }
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;
  }
1029848
public function getHeader($header)
	{
		$n = ($header instanceof HttpHeaderInterface) ? strtolower($header->getFieldName()) : strtolower($header);
		
		if(!empty($this->headers[$n]))
		{
			return $this->headers[$n][0][1];
		}
		
		if(func_num_args() > 1)
		{
			return func_get_arg(1);
		}
		
		$name = ($header instanceof HttpHeaderInterface) ? $header->getFieldName() : $header;
		
		throw new \OutOfBoundsException(sprintf('HTTP header not found: "%s"', $name));
	}
892610
public function getHeader($header)
    {
        $header = ucwords(strtolower($header));
        if (! is_string($header) || ! isset($this->headers[$header])) return null;

        return $this->headers[$header];
    }
858666
protected function getHeaderStrArr($header)
    {
        $headerStr = [];
        foreach ($header as $co => $vo) {
            $headerStr[] = $this->ucWords($co) . ': ' . $vo;
        }
        return $headerStr;
    }
48906
public function header($header = null) {
			if ($this->_status != null) {
				array_push($this->_headers, $header);
				return true;
			}
			else {
				return $this->_headers;
			}
		}
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;
    }
1281279
public function setHeader($header)
    {
        $headers = [];

        if (is_array($header)) {
            foreach ($header as $key => $value) {
                $headers[] = $key . ': ' . $value;
            }
        } else {
            $headers[] = $header;
        }

        $this->setOpt(CURLOPT_HTTPHEADER, $headers);

        return $this;
    }
473734
protected function parseHeader($responseHeader)
    {

        $filtered = [];

        foreach ((array)$responseHeader as $header) {
            if (stripos($header, 'http/')) {
                $filtered = [];
            }
            $filtered[] = $header;
        }

        return $filtered;
    }