Tries to find the http status code in its header.

@param $headers

@return int
545392
protected function findStatusInHeaders($headers)
    {
        if (!isset($headers[0]) || strpos($headers[0], 'HTTP/') !== 0) {
            throw new UnexpectedValueException('Invalid HTTP Headers, missing status line');
        }

        $parts = explode(' ', trim($headers[0]));

        return (int)trim($parts[1]);
    }
936873
private function getHeader(ConfigObject $annotations)
    {
        // headers status code depends on the request method type, unless it's forced on the class or method
        $successStatus = $annotations->get('header.status.success', false);
        if (!$successStatus) {
            $successStatus = $this->classDefaults->get('header.status.success', false);

            if (!$successStatus) {
                $method = strtolower($annotations->get('method', $this->classDefaults->get('method', 'get')));
                if ($method == 'post') {
                    $successStatus = 201;
                } else {
                    $successStatus = 200;
                }
            }
        }

        return [
            'cache'  => [
                'expires' => $annotations->get('header.cache.expires',
                    $this->classDefaults->get('header.cache.expires', 0))
            ],
            'status' => [
                'success'      => $successStatus,
                'error'        => $annotations->get('header.status.error',
                    $this->classDefaults->get('header.status.error', 404)),
                'errorMessage' => $annotations->get('header.status.errorMessage',
                    $this->classDefaults->get('header.status.errorMessage', ''))
            ]
        ];
    }
669865
public static function getHTTPStatusCode($header)
  {
    $first_line = strtok($header, "\n");
    
    preg_match("# [0-9]{3}#", $first_line, $match);
    
    if (isset($match[0]))
      return (int)trim($match[0]);
    else
      return null;
  }
651048
public function setHeaders($headers)
    {
        foreach ($headers as $key => $value) {
            $this->headers[$key] = $value;
        }

        $headers = array();
        foreach ($this->headers as $key => $value) {
            $headers[] = $key . ': ' . $value;
        }
        $this->setOpt(CURLOPT_HTTPHEADER, $headers);
    }
270851
public function headers($headers = null)
    {
        if (!func_num_args()) {
            return $this->_headers;
        }
        $this->_headers = $headers;
        return $this;
    }
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) : [];
    }
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');
    }
499031
public function status($code = 200)
    {
        if (!isset(self::$codes[$code])) {
            return false;
        }
        $this->header($code . ' ' . self::$codes[$code]);
        return true;
    }
1182217
public function setHeaders($headers)
    {
        if (!empty($this->headers)) {
            $this->headers = array_merge($this->headers, $headers);
        } else {
            $this->headers = $headers;
        }
        $this->headers = array_merge($this->headers, $headers);

        if ($this->client instanceof \swoole_http_client) {
            $this->client->setHeaders($this->headers);
        }
        return $this;
    }
943378
public function getToken(IHttpHeaders $headers) {
        $header = $this->getHeader($headers);

        return $this->parseHeader($header);
    }
101424
protected function parserHttpHeadersAsArray($rawHeaders)
    {
        $headers = array();

        foreach(explode("\n", $rawHeaders) as $i => $line)
        {
            if($i == 0)
            {
                $headers['HTTP_STATUS'] = substr($line, 9, 3);
            }
            else
            {
                list($key, $value) = explode(': ', $line);
                $headers[trim($key)] = trim($value);
            }
        }

        return $headers;
    }
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];
    }
661357
private function parseHttpHeaders($rawHeaders) {
		// ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986
		$headers = array();
		$key = '';

		foreach (explode("\n", $rawHeaders) as $h) {
			$h = explode(':', $h, 2);

			if (isset($h[1])) {
				if (!isset($headers[$h[0]])) {
					$headers[$h[0]] = trim($h[1]);
				} elseif (is_array($headers[$h[0]])) {
					$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1])));
				} else {
					$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1])));
				}

				$key = $h[0];
			} else {
				if (substr($h[0], 0, 1) === "\t") {
					$headers[$key] .= "\r\n\t".trim($h[0]);
				} elseif (!$key) {
					$headers[0] = trim($h[0]);
				}
				trim($h[0]);
			}
		}

		return $headers;
	}
1092982
public function determineHeaderStringForSignedRequest(array $headers): string
    {
        $signedDataHeaderString = self::SIGNED_DATA_EMPTY_STRING;
        ksort($headers);

        foreach ($headers as $headerName => $headerValue) {
            // Not all headers should be signed.
            // The User-Agent and Cache-Control headers need to be signed.
            if ($headerName === self::HEADER_USER_AGENT || $headerName === self::HEADER_CACHE_CONTROL) {
                $signedDataHeaderString .= self::NEWLINE;
                $signedDataHeaderString .= $this->determineHeaderStringLine($headerName, $headerValue);
            }

            // All headers with the prefix 'X-Bunq-' except 'Server-Signature' need to be signed.
            if ($headerName === self::HEADER_SERVER_SIGNATURE) {
                // Skip this header
            } elseif (strpos($headerName, self::HEADER_PREFIX) === self::HEADER_PREFIX_START) {
                $signedDataHeaderString .= self::NEWLINE;
                $signedDataHeaderString .= $this->determineHeaderStringLine($headerName, $headerValue);
            }
        }

        return $signedDataHeaderString;
    }
740260
private function parseHeaders($raw_headers)
    {
        $raw_headers = preg_split('/\r\n/', $raw_headers, null, PREG_SPLIT_NO_EMPTY);
        $http_headers = [];

        $raw_headers_count = count($raw_headers);
        for ($i = 1; $i < $raw_headers_count; $i++) {
            list($key, $value) = explode(':', $raw_headers[$i], 2);
            $key = trim($key);
            $value = trim($value);
            // Use isset() as array_key_exists() and ArrayAccess are not compatible.
            if (isset($http_headers[$key])) {
                $http_headers[$key] .= ',' . $value;
            } else {
                $http_headers[$key] = $value;
            }
        }

        return array(isset($raw_headers['0']) ? $raw_headers['0'] : '', $http_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;
    }
1090291
public function getHeader($header) {
		foreach($this->headers as $k => $v) {
			if($v[0] === $header)
				return $v;
		}
	}