#56 headers get mixed into data (short timeouts on slow servers)

open
nobody
None
5
2006-05-04
2006-05-04
Beat
No

Actually, there is a bug when the headers reading timeouts, the
headers are read into the data results !

This:
while($currentHeader = fgets($fp,$this->_maxlinelen))
{
...
}
$results = '';
do {
$_data = fread($fp, $this->maxlength);
if (strlen($_data) == 0) {
...

should be changed to that:

while($currentHeader = fgets($fp,$this->_maxlinelen))
{
...

}

// 4 lines added to fix problem that on timeout of header,
and not timeout of read-data, data returned includes header:
if ($currentHeader === false) {
$this->status=-100;
return false;
}

$results = '';
do {
$_data = fread($fp, $this->maxlength);
if (strlen($_data) == 0) {
...

Indeed, according to fgets() php.net specs, it returns false on errors
(like timeouts).

Otherwise it sometimes returns the http headers in the data.... !

Discussion