stream webdav downloads using http client
This commit is contained in:
parent
b67d395089
commit
df8cb2cc63
|
@ -40,6 +40,7 @@ use OC\Files\Filesystem;
|
||||||
use OC\Files\Stream\Close;
|
use OC\Files\Stream\Close;
|
||||||
use Icewind\Streams\IteratorDirectory;
|
use Icewind\Streams\IteratorDirectory;
|
||||||
use OC\MemCache\ArrayCache;
|
use OC\MemCache\ArrayCache;
|
||||||
|
use OCP\AppFramework\Http;
|
||||||
use OCP\Constants;
|
use OCP\Constants;
|
||||||
use OCP\Files;
|
use OCP\Files;
|
||||||
use OCP\Files\FileInfo;
|
use OCP\Files\FileInfo;
|
||||||
|
@ -337,38 +338,23 @@ class DAV extends Common {
|
||||||
if (!$this->file_exists($path)) {
|
if (!$this->file_exists($path)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//straight up curl instead of sabredav here, sabredav put's the entire get result in memory
|
$httpClient = \OC::$server->getHTTPClientService();
|
||||||
$curl = curl_init();
|
$response = $httpClient
|
||||||
$fp = fopen('php://temp', 'r+');
|
->newClient()
|
||||||
curl_setopt($curl, CURLOPT_USERPWD, $this->user . ':' . $this->password);
|
->get($this->createBaseUri() . $this->encodePath($path), [
|
||||||
curl_setopt($curl, CURLOPT_URL, $this->createBaseUri() . $this->encodePath($path));
|
'auth' => [$this->user, $this->password],
|
||||||
curl_setopt($curl, CURLOPT_FILE, $fp);
|
'stream' => true
|
||||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
]);
|
||||||
if(defined('CURLOPT_PROTOCOLS')) {
|
|
||||||
curl_setopt($curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
if ($response->getStatusCode() !== Http::STATUS_OK) {
|
||||||
}
|
if ($response->getStatusCode() === Http::STATUS_LOCKED) {
|
||||||
if(defined('CURLOPT_REDIR_PROTOCOLS')) {
|
throw new \OCP\Lock\LockedException($path);
|
||||||
curl_setopt($curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
|
} else {
|
||||||
}
|
Util::writeLog("webdav client", 'Guzzle get returned status code ' . $response->getStatusCode(), Util::ERROR);
|
||||||
if ($this->secure === true) {
|
|
||||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
|
|
||||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
|
|
||||||
if ($this->certPath) {
|
|
||||||
curl_setopt($curl, CURLOPT_CAINFO, $this->certPath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_exec($curl);
|
return $response->getBody();
|
||||||
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
||||||
if ($statusCode !== 200) {
|
|
||||||
Util::writeLog("webdav client", 'curl GET ' . curl_getinfo($curl, CURLINFO_EFFECTIVE_URL) . ' returned status code ' . $statusCode, Util::ERROR);
|
|
||||||
if ($statusCode === 423) {
|
|
||||||
throw new \OCP\Lock\LockedException($path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
curl_close($curl);
|
|
||||||
rewind($fp);
|
|
||||||
return $fp;
|
|
||||||
case 'w':
|
case 'w':
|
||||||
case 'wb':
|
case 'wb':
|
||||||
case 'a':
|
case 'a':
|
||||||
|
|
Loading…
Reference in New Issue