# HG changeset patch # User Dan # Date 1270233735 14400 # Node ID 903bb153c2652afb4c7834d18a85117ce69b7ed7 # Parent 202b25e2d0e6e710759911d65a97ddbb2f348854 Fixed fread() usage in Request_HTTP not properly handling incomplete responses diff -r 202b25e2d0e6 -r 903bb153c265 includes/http.php --- a/includes/http.php Thu Apr 01 19:57:23 2010 -0500 +++ b/includes/http.php Fri Apr 02 14:42:15 2010 -0400 @@ -370,10 +370,8 @@ $newline = "\r\n"; if ( $this->debug ) + { echo '

Connection opened. Writing main request to socket. Raw socket data follows.

';
-		
-		if ( $this->debug )
-		{
 			echo '
'; echo '

' . __CLASS__ . ': Sending request

Request parameters:

'; echo "

Headers:

$headers
"; @@ -386,7 +384,7 @@ $portline = ( $this->port == 80 ) ? '' : ":$this->port"; $this->_fputs($connection, "{$this->method} {$this->uri}{$get} HTTP/1.1{$newline}"); - $this->_fputs($connection, "Host: {$this->host}$portline{$newline}"); + $this->_fputs($connection, "Host: {$this->host}{$portline}{$newline}"); $this->_fputs($connection, $headers); $this->_fputs($connection, $cookies); @@ -528,7 +526,17 @@ { echo "Pulling response using fread(), size $size\n"; } - $this->response .= fread($this->socket, $size); + $basesize = strlen($this->response); + while ( strlen($this->response) - $basesize < $size ) + { + $remaining_bytes = $size - (strlen($this->response) - $basesize); + $this->response .= fread($this->socket, $remaining_bytes); + if ( $this->debug ) + { + $remaining_bytes = $size - (strlen($this->response) - $basesize); + echo "
Received " . (strlen($this->response) - $basesize) . " of $size bytes ($remaining_bytes remaining)...\n"; + } + } } else {