import v1.1.0_beta1 | 2009-08-21

This commit is contained in:
2019-07-17 22:16:19 +02:00
parent 2c1152f0d3
commit 8dee6b1a10
2306 changed files with 251360 additions and 23428 deletions

View File

@ -16,7 +16,7 @@
* @category Zend
* @package Zend_Http
* @subpackage Client_Adapter
* @version $Id: Socket.php 12105 2008-10-23 23:38:55Z shahar $
* @version $Id: Socket.php 13013 2008-12-04 12:04:24Z yoshida@zend.co.jp $
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
@ -135,7 +135,7 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
$flags = STREAM_CLIENT_CONNECT;
if ($this->config['persistent']) $flags |= STREAM_CLIENT_PERSISTENT;
$this->socket = @stream_socket_client($host . ':' . $port,
$errno,
$errstr,
@ -228,7 +228,7 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
}
$statusCode = Zend_Http_Response::extractCode($response);
// Handle 100 and 101 responses internally by restarting the read again
if ($statusCode == 100 || $statusCode == 101) return $this->read();
@ -236,7 +236,7 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
* Responses to HEAD requests and 204 or 304 responses are not expected
* to have a body - stop reading here
*/
if ($statusCode == 304 || $statusCode == 204 ||
if ($statusCode == 304 || $statusCode == 204 ||
$this->method == Zend_Http_Client::HEAD) return $response;
// Check headers to see what kind of connection / transfer encoding we have
@ -260,14 +260,19 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
// Convert the hexadecimal value to plain integer
$chunksize = hexdec($chunksize);
// Read chunk
$left_to_read = $chunksize;
while ($left_to_read > 0) {
$line = @fread($this->socket, $left_to_read);
$chunk .= $line;
$left_to_read -= strlen($line);
if ($line === false || strlen($line) === 0)
{
break;
} else {
$chunk .= $line;
$left_to_read -= strlen($line);
}
// Break if the connection ended prematurely
if (feof($this->socket)) break;
}
@ -275,35 +280,45 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
$chunk .= @fgets($this->socket);
$response .= $chunk;
} while ($chunksize > 0);
} else {
throw new Zend_Http_Client_Adapter_Exception('Cannot handle "' .
$headers['transfer-encoding'] . '" transfer encoding');
}
// Else, if we got the content-length header, read this number of bytes
} elseif (isset($headers['content-length'])) {
$left_to_read = $headers['content-length'];
$chunk = '';
while ($left_to_read > 0) {
$chunk = @fread($this->socket, $left_to_read);
$left_to_read -= strlen($chunk);
$response .= $chunk;
if ($chunk === false || strlen($chunk) === 0)
{
break;
} else {
$left_to_read -= strlen($chunk);
$response .= $chunk;
}
// Break if the connection ended prematurely
if (feof($this->socket)) break;
}
// Fallback: just read the response until EOF
} else {
while (($buff = @fread($this->socket, 8192)) !== false) {
$response .= $buff;
if (feof($this->socket)) break;
}
do {
$buff = @fread($this->socket, 8192);
if ($buff === false || strlen($buff) === 0)
{
break;
} else {
$response .= $buff;
}
} while (feof($this->socket) === false);
$this->close();
}
// Close the connection if requested to do so by the server
if (isset($headers['connection']) && $headers['connection'] == 'close') {
$this->close();
@ -324,8 +339,8 @@ class Zend_Http_Client_Adapter_Socket implements Zend_Http_Client_Adapter_Interf
}
/**
* Destructor: make sure the socket is disconnected
*
* Destructor: make sure the socket is disconnected
*
* If we are in persistent TCP mode, will not close the connection
*
*/