From 06f945f27840b53e57795dadbc38e76f7e11ab1c Mon Sep 17 00:00:00 2001 From: Horus3 Date: Mon, 24 Feb 2014 16:42:14 +0100 Subject: init --- .../Zend/Gdata/HttpAdapterStreamingSocket.php | 111 +++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 zend/library/Zend/Gdata/HttpAdapterStreamingSocket.php (limited to 'zend/library/Zend/Gdata/HttpAdapterStreamingSocket.php') diff --git a/zend/library/Zend/Gdata/HttpAdapterStreamingSocket.php b/zend/library/Zend/Gdata/HttpAdapterStreamingSocket.php new file mode 100644 index 0000000..c89e67b --- /dev/null +++ b/zend/library/Zend/Gdata/HttpAdapterStreamingSocket.php @@ -0,0 +1,111 @@ +socket) { + require_once 'Zend/Http/Client/Adapter/Exception.php'; + throw new Zend_Http_Client_Adapter_Exception( + 'Trying to write but we are not connected'); + } + + $host = $uri->getHost(); + $host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host; + if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) { + require_once 'Zend/Http/Client/Adapter/Exception.php'; + throw new Zend_Http_Client_Adapter_Exception( + 'Trying to write but we are connected to the wrong host'); + } + + // Save request method for later + $this->method = $method; + + // Build request headers + $path = $uri->getPath(); + if ($uri->getQuery()) $path .= '?' . $uri->getQuery(); + $request = "{$method} {$path} HTTP/{$http_ver}\r\n"; + foreach ($headers as $k => $v) { + if (is_string($k)) $v = ucfirst($k) . ": $v"; + $request .= "$v\r\n"; + } + + // Send the headers over + $request .= "\r\n"; + if (! @fwrite($this->socket, $request)) { + require_once 'Zend/Http/Client/Adapter/Exception.php'; + throw new Zend_Http_Client_Adapter_Exception( + 'Error writing request to server'); + } + + + //read from $body, write to socket + $chunk = $body->read(self::CHUNK_SIZE); + while ($chunk !== FALSE) { + if (! @fwrite($this->socket, $chunk)) { + require_once 'Zend/Http/Client/Adapter/Exception.php'; + throw new Zend_Http_Client_Adapter_Exception( + 'Error writing request to server'); + } + $chunk = $body->read(self::CHUNK_SIZE); + } + $body->closeFileHandle(); + return 'Large upload, request is not cached.'; + } +} -- cgit v1.2.3