|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00027 require_once 'Zend/Http/Client/Adapter/Socket.php'; 00028 00039 class Zend_Gdata_HttpAdapterStreamingSocket extends Zend_Http_Client_Adapter_Socket 00040 { 00041 00047 const CHUNK_SIZE = 1024; 00048 00059 public function write($method, $uri, $http_ver = '1.1', $headers = array(), 00060 $body = '') 00061 { 00062 // Make sure we're properly connected 00063 if (! $this->socket) { 00064 require_once 'Zend/Http/Client/Adapter/Exception.php'; 00065 throw new Zend_Http_Client_Adapter_Exception( 00066 'Trying to write but we are not connected'); 00067 } 00068 00069 $host = $uri->getHost(); 00070 $host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host; 00071 if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) { 00072 require_once 'Zend/Http/Client/Adapter/Exception.php'; 00073 throw new Zend_Http_Client_Adapter_Exception( 00074 'Trying to write but we are connected to the wrong host'); 00075 } 00076 00077 // Save request method for later 00078 $this->method = $method; 00079 00080 // Build request headers 00081 $path = $uri->getPath(); 00082 if ($uri->getQuery()) $path .= '?' . $uri->getQuery(); 00083 $request = "{$method} {$path} HTTP/{$http_ver}\r\n"; 00084 foreach ($headers as $k => $v) { 00085 if (is_string($k)) $v = ucfirst($k) . ": $v"; 00086 $request .= "$v\r\n"; 00087 } 00088 00089 // Send the headers over 00090 $request .= "\r\n"; 00091 if (! @fwrite($this->socket, $request)) { 00092 require_once 'Zend/Http/Client/Adapter/Exception.php'; 00093 throw new Zend_Http_Client_Adapter_Exception( 00094 'Error writing request to server'); 00095 } 00096 00097 00098 //read from $body, write to socket 00099 $chunk = $body->read(self::CHUNK_SIZE); 00100 while ($chunk !== FALSE) { 00101 if (! @fwrite($this->socket, $chunk)) { 00102 require_once 'Zend/Http/Client/Adapter/Exception.php'; 00103 throw new Zend_Http_Client_Adapter_Exception( 00104 'Error writing request to server'); 00105 } 00106 $chunk = $body->read(self::CHUNK_SIZE); 00107 } 00108 $body->closeFileHandle(); 00109 return 'Large upload, request is not cached.'; 00110 } 00111 }