src/_legacyCode/HttpRequest.php
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');
    }
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');
    }
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'); }
Parses HTTP header & populates http headers

@param string $header HTTP request header including status line & all headers

@throws HttpException Raised if request header is not RFC-complaint
Parses HTTP header & populates http headers