src/Generics/Client/HttpClientTrait.php
private function retrieveAndParseResponse($requestType)
    {
        $this->payload = new MemoryStream();
        $this->headers = array();
        
        $delimiterFound = false;
        
        $tmp = "";
        $numBytes = 1;
        $start = time();
        while (true) {
            if (! $this->checkConnection($start)) {
                continue;
            }
            
            $c = $this->read($numBytes);
            
            if ($c == null) {
                break;
            }
            
            $start = time(); // we have readen something => adjust timeout start point
            $tmp .= $c;
            
            if (! $delimiterFound) {
                $this->handleHeader($delimiterFound, $numBytes, $tmp);
            }
            
            if ($delimiterFound) {
                if ($requestType == 'HEAD') {
                    // Header readen, in type HEAD it is now time to leave
                    break;
                }
                
                // delimiter already found, append to payload
                $this->payload->write($tmp);
                $tmp = "";
                
                if ($this->checkContentLengthExceeded()) {
                    break;
                }
            }
        }
        
        $size = $this->payload->count();
        if ($size == 0) {
            return;
        }
        // Set pointer to start
        $this->payload->reset();
        
        $mayCompressed = $this->payload->read($size);
        switch ($this->getContentEncoding()) {
            case 'gzip':
                $uncompressed = gzdecode(strstr($mayCompressed, "\x1f\x8b"));
                $this->payload->flush();
                $this->payload->write($uncompressed);
                break;
            
            case 'deflate':
                $uncompressed = gzuncompress($mayCompressed);
                $this->payload->flush();
                $this->payload->write($uncompressed);
                break;
            
            default:
                // nothing
                break;
        }
        $this->payload->reset();
    }
private function retrieveAndParseResponse($requestType)
    {
        $this->payload = new MemoryStream();
        $this->headers = array();
        
        $delimiterFound = false;
        
        $tmp = "";
        $numBytes = 1;
        $start = time();
        while (true) {
            if (! $this->checkConnection($start)) {
                continue;
            }
            
            $c = $this->read($numBytes);
            
            if ($c == null) {
                break;
            }
            
            $start = time(); // we have readen something => adjust timeout start point
            $tmp .= $c;
            
            if (! $delimiterFound) {
                $this->handleHeader($delimiterFound, $numBytes, $tmp);
            }
            
            if ($delimiterFound) {
                if ($requestType == 'HEAD') {
                    // Header readen, in type HEAD it is now time to leave
                    break;
                }
                
                // delimiter already found, append to payload
                $this->payload->write($tmp);
                $tmp = "";
                
                if ($this->checkContentLengthExceeded()) {
                    break;
                }
            }
        }
        
        $size = $this->payload->count();
        if ($size == 0) {
            return;
        }
        // Set pointer to start
        $this->payload->reset();
        
        $mayCompressed = $this->payload->read($size);
        switch ($this->getContentEncoding()) {
            case 'gzip':
                $uncompressed = gzdecode(strstr($mayCompressed, "\x1f\x8b"));
                $this->payload->flush();
                $this->payload->write($uncompressed);
                break;
            
            case 'deflate':
                $uncompressed = gzuncompress($mayCompressed);
                $this->payload->flush();
                $this->payload->write($uncompressed);
                break;
            
            default:
                // nothing
                break;
        }
        $this->payload->reset();
    }
Retrieve and parse the response

@param string $requestType
@throws \Generics\Client\HttpException
@throws \Generics\Socket\SocketException
@throws \Generics\Streams\StreamException