Changeset 1870
- Timestamp:
- 09/30/08 16:10:21 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
framework/trunk/src/main/php/net/stubbles/peer/http/stubHTTPResponse.php
r1763 r1870 141 141 $header .= $line; 142 142 } 143 143 144 144 $this->headers = stubHeaderList::fromString($header); 145 145 return $this; … … 157 157 throw new stubIllegalAccessException('Need to read response headers first.'); 158 158 } 159 159 160 160 if ($this->headers->get('Transfer-Encoding') === 'chunked') { 161 161 $this->body = $this->readChunked(); … … 163 163 $this->body = $this->readDefault($this->headers->get('Content-Length', 4096)); 164 164 } 165 165 166 166 return $this; 167 167 } … … 191 191 sscanf($this->socket->read(1024), "%x\r\n", $chunksize); 192 192 } 193 193 194 194 #read entity-header 195 195 #while (entity-header not empty) { … … 197 197 # read entity-header 198 198 #} 199 199 200 200 // set correct content length 201 201 $this->headers->put('Content-Length', $readLength); … … 213 213 protected function readDefault($readLength) 214 214 { 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)); 221 216 } 222 217 … … 232 227 return $this->response[$type]; 233 228 } 234 229 235 230 return null; 236 231 } … … 253 248 } 254 249 } 255 250 256 251 return $types; 257 252 } … … 298 293 return; 299 294 } 300 295 301 296 $this->response[self::TYPE_STATUS_LINE] = $matches[0]; 302 297 $this->response[self::TYPE_HTTP_VERSION] = $matches[1]; … … 307 302 $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_INFO; 308 303 break; 309 304 310 305 case 2: 311 306 $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_SUCCESS; 312 307 break; 313 308 314 309 case 3: 315 310 $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_REDIRECT; 316 311 break; 317 312 318 313 case 4: 319 314 $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_ERROR_CLIENT; 320 315 break; 321 316 322 317 case 5: 323 318 $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_ERROR_SERVER; 324 319 break; 325 320 326 321 default: 327 322 $this->response[self::TYPE_STATUS_CLASS] = self::STATUS_CLASS_UNKNOWN; framework/trunk/src/test/php/net/stubbles/peer/http/stubHTTPResponseTestCase.php
r1763 r1870 308 308 public function defaultReading() 309 309 { 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()) 314 311 ->method('read') 315 312 ->with($this->equalTo(4096)) 316 ->will($this-> onConsecutiveCalls('foo', 'bar'));313 ->will($this->returnValue('foobar')); 317 314 $this->assertEquals('foobar', $this->httpResponse->callReadDefault(4096)); 318 315 }
