private function readChunked(): string
    {
        $readLength = 0;
        $chunksize  = null;
        $extension  = null;
        $body       = '';
        sscanf($this->socket->readLine(), '%x%s', $chunksize, $extension);
        while (0 < $chunksize) {
            $data        = $this->socket->read($chunksize + 4);
            $body       .= rtrim($data);
            $readLength += $chunksize;
            sscanf($this->socket->readLine(), '%x', $chunksize);
        }

        $this->headers->put('Content-Length', $readLength);
        $this->headers->remove('Transfer-Encoding');
        return $body;
    }
private function readChunked(): string
    {
        $readLength = 0;
        $chunksize  = null;
        $extension  = null;
        $body       = '';
        sscanf($this->socket->readLine(), '%x%s', $chunksize, $extension);
        while (0 < $chunksize) {
            $data        = $this->socket->read($chunksize + 4);
            $body       .= rtrim($data);
            $readLength += $chunksize;
            sscanf($this->socket->readLine(), '%x', $chunksize);
        }

        $this->headers->put('Content-Length', $readLength);
        $this->headers->remove('Transfer-Encoding');
        return $body;
    }
private function readChunked ( ) : string { $ readLength = 0 ; $ chunksize = null ; $ extension = null ; $ body = '' ; sscanf ( $ this -> socket -> readLine ( ) , '%x%s' , $ chunksize , $ extension ) ; while ( 0 < $ chunksize ) { $ data = $ this -> socket -> read ( $ chunksize + 4 ) ; $ body .= rtrim ( $ data ) ; $ readLength += $ chunksize ; sscanf ( $ this -> socket -> readLine ( ) , '%x' , $ chunksize ) ; } $ this -> headers -> put ( 'Content-Length' , $ readLength ) ; $ this -> headers -> remove ( 'Transfer-Encoding' ) ; return $ body ; }
helper method to read chunked response body

The method implements the pseudo code given in RFC 2616 section 19.4.6:
Introduction of Transfer-Encoding. Chunk extensions are ignored.

@return  string
helper method to read chunked response body