|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00027 require_once 'Zend/Http/Client/Adapter/Proxy.php'; 00028 00039 class Zend_Gdata_HttpAdapterStreamingProxy extends Zend_Http_Client_Adapter_Proxy 00040 { 00046 const CHUNK_SIZE = 1024; 00047 00058 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '') 00059 { 00060 // If no proxy is set, throw an error 00061 if (! $this->config['proxy_host']) { 00062 require_once 'Zend/Http/Client/Adapter/Exception.php'; 00063 throw new Zend_Http_Client_Adapter_Exception('No proxy host set!'); 00064 } 00065 00066 // Make sure we're properly connected 00067 if (! $this->socket) { 00068 require_once 'Zend/Http/Client/Adapter/Exception.php'; 00069 throw new Zend_Http_Client_Adapter_Exception( 00070 'Trying to write but we are not connected'); 00071 } 00072 00073 $host = $this->config['proxy_host']; 00074 $port = $this->config['proxy_port']; 00075 00076 if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) { 00077 require_once 'Zend/Http/Client/Adapter/Exception.php'; 00078 throw new Zend_Http_Client_Adapter_Exception( 00079 'Trying to write but we are connected to the wrong proxy ' . 00080 'server'); 00081 } 00082 00083 // Add Proxy-Authorization header 00084 if ($this->config['proxy_user'] && ! isset($headers['proxy-authorization'])) { 00085 $headers['proxy-authorization'] = Zend_Http_Client::encodeAuthHeader( 00086 $this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth'] 00087 ); 00088 } 00089 00090 // if we are proxying HTTPS, preform CONNECT handshake with the proxy 00091 if ($uri->getScheme() == 'https' && (! $this->negotiated)) { 00092 $this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers); 00093 $this->negotiated = true; 00094 } 00095 00096 // Save request method for later 00097 $this->method = $method; 00098 00099 // Build request headers 00100 $request = "{$method} {$uri->__toString()} HTTP/{$http_ver}\r\n"; 00101 00102 // Add all headers to the request string 00103 foreach ($headers as $k => $v) { 00104 if (is_string($k)) $v = "$k: $v"; 00105 $request .= "$v\r\n"; 00106 } 00107 00108 $request .= "\r\n"; 00109 00110 // Send the request headers 00111 if (! @fwrite($this->socket, $request)) { 00112 require_once 'Zend/Http/Client/Adapter/Exception.php'; 00113 throw new Zend_Http_Client_Adapter_Exception( 00114 'Error writing request to proxy server'); 00115 } 00116 00117 //read from $body, write to socket 00118 while ($body->hasData()) { 00119 if (! @fwrite($this->socket, $body->read(self::CHUNK_SIZE))) { 00120 require_once 'Zend/Http/Client/Adapter/Exception.php'; 00121 throw new Zend_Http_Client_Adapter_Exception( 00122 'Error writing request to server'); 00123 } 00124 } 00125 return 'Large upload, request is not cached.'; 00126 } 00127 }