Changeset 1870

Show
Ignore:
Timestamp:
09/30/08 16:10:21 (3 months ago)
Author:
prema
Message:

FIX:

  • change implementation of socket reading by stubHTTPResponse
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework/trunk/src/main/php/net/stubbles/peer/http/stubHTTPResponse.php

    r1763 r1870  
    141141            $header .= $line; 
    142142        } 
    143          
     143 
    144144        $this->headers = stubHeaderList::fromString($header); 
    145145        return $this; 
     
    157157            throw new stubIllegalAccessException('Need to read response headers first.'); 
    158158        } 
    159          
     159 
    160160        if ($this->headers->get('Transfer-Encoding') === 'chunked') { 
    161161            $this->body = $this->readChunked(); 
     
    163163            $this->body = $this->readDefault($this->headers->get('Content-Length', 4096)); 
    164164        } 
    165          
     165 
    166166        return $this; 
    167167    } 
     
    191191            sscanf($this->socket->read(1024), "%x\r\n", $chunksize); 
    192192        } 
    193          
     193 
    194194        #read entity-header 
    195195        #while (entity-header not empty) { 
     
    197197        #    read entity-header 
    198198        #} 
    199          
     199 
    200200        // set correct content length 
    201201        $this->headers->put('Content-Length', $readLength); 
     
    213213    protected function readDefault($readLength) 
    214214    { 
    215         $body = ''; 
    216         while ($this->socket->eof() === false) { 
    217             $body .= $this->socket->read($readLength); 
    218         } 
    219          
    220         return $body; 
     215        return ($body = $this->socket->read($readLength)); 
    221216    } 
    222217 
     
    232227            return $this->response[$type]; 
    233228        } 
    234          
     229 
    235230        return null; 
    236231    } 
     
    253248            } 
    254249        } 
    255          
     250 
    256251        return $types; 
    257252    } 
     
    298293            return; 
    299294        } 
    300          
     295 
    301296        $this->response[self::TYPE_STATUS_LINE]   = $matches[0]; 
    302297        $this->response[self::TYPE_HTTP_VERSION]  = $matches[1]; 
     
    307302                $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_INFO; 
    308303                break; 
    309              
     304 
    310305            case 2: 
    311306                $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_SUCCESS; 
    312307                break; 
    313              
     308 
    314309            case 3: 
    315310                $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_REDIRECT; 
    316311                break; 
    317              
     312 
    318313            case 4: 
    319314                $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_ERROR_CLIENT; 
    320315                break; 
    321              
     316 
    322317            case 5: 
    323318                $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_ERROR_SERVER; 
    324319                break; 
    325              
     320 
    326321            default: 
    327322                $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_UNKNOWN; 
  • framework/trunk/src/test/php/net/stubbles/peer/http/stubHTTPResponseTestCase.php

    r1763 r1870  
    308308    public function defaultReading() 
    309309    { 
    310         $this->mockSocket->expects($this->exactly(3)) 
    311                          ->method('eof') 
    312                          ->will($this->onConsecutiveCalls(false, false, true)); 
    313         $this->mockSocket->expects($this->exactly(2)) 
     310        $this->mockSocket->expects($this->once()) 
    314311                         ->method('read') 
    315312                         ->with($this->equalTo(4096)) 
    316                          ->will($this->onConsecutiveCalls('foo', 'bar')); 
     313                         ->will($this->returnValue('foobar')); 
    317314        $this->assertEquals('foobar', $this->httpResponse->callReadDefault(4096)); 
    318315    }