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

None
open
nobody
None
5
2015-05-31
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.... !

Related

Bugs: #79

Discussion

  • Gene Wood
    Gene Wood
    2015-05-31

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -2,36 +2,37 @@
     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\) \{
    -...
    +
    +    :::php
    +    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\)\)
    -\{
    -...
    +    :::php
    +    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;
    +    }
    
    -// 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\) \{
    -...
    +    $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\).
    
    • Group: -->
     
  • Gene Wood
    Gene Wood
    2015-05-31

    I've updated Snoopy with this check to catch this case, where the header fetch times out but the body succeeds, and pulls the headers into the body.

    This is committed at revision 1.36 but not yet packaged up for release.