summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2017-12-11 15:28:05 +0100
committerGitHub <noreply@github.com>2017-12-11 15:28:05 +0100
commite47137c7d4a57b20bc2ed337aaee4cf99ee94e08 (patch)
tree5dd56274dd47d4fe35a44edfda32ae1448e8c21c
parentc1fcd6fc98c43c7a0298d68e1c2533132b12176d (diff)
parentb36dd8b71fb8751b07ef98443d739d0b1cda9c7d (diff)
downloadnextcloud-server-e47137c7d4a57b20bc2ed337aaee4cf99ee94e08.tar.gz
nextcloud-server-e47137c7d4a57b20bc2ed337aaee4cf99ee94e08.zip
Merge pull request #6682 from nextcloud/dav-mimetype-fallback
Fallback to filename based detection if the remote dav server doesn't…
-rw-r--r--apps/files_external/tests/Storage/WebdavTest.php13
-rw-r--r--lib/private/Files/Storage/DAV.php26
2 files changed, 29 insertions, 10 deletions
diff --git a/apps/files_external/tests/Storage/WebdavTest.php b/apps/files_external/tests/Storage/WebdavTest.php
index 1e518e23b77..b007ded2662 100644
--- a/apps/files_external/tests/Storage/WebdavTest.php
+++ b/apps/files_external/tests/Storage/WebdavTest.php
@@ -28,6 +28,7 @@
namespace OCA\Files_External\Tests\Storage;
use \OC\Files\Storage\DAV;
+use OC\Files\Type\Detection;
/**
* Class WebdavTest
@@ -43,7 +44,7 @@ class WebdavTest extends \Test\Files\Storage\Storage {
$id = $this->getUniqueID();
$config = include('files_external/tests/config.webdav.php');
- if ( ! is_array($config) or !$config['run']) {
+ if (!is_array($config) or !$config['run']) {
$this->markTestSkipped('WebDAV backend not configured');
}
if (isset($config['wait'])) {
@@ -61,4 +62,14 @@ class WebdavTest extends \Test\Files\Storage\Storage {
parent::tearDown();
}
+
+ public function testMimetypeFallback() {
+ $this->instance->file_put_contents('foo.bar', 'asd');
+
+ /** @var Detection $mimeDetector */
+ $mimeDetector = \OC::$server->getMimeTypeDetector();
+ $mimeDetector->registerType('bar', 'application/x-bar');
+
+ $this->assertEquals('application/x-bar', $this->instance->getMimeType('foo.bar'));
+ }
}
diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php
index cd42b2d7073..6585dd862e4 100644
--- a/lib/private/Files/Storage/DAV.php
+++ b/lib/private/Files/Storage/DAV.php
@@ -146,7 +146,7 @@ class DAV extends Common {
}
$proxy = \OC::$server->getConfig()->getSystemValue('proxy', '');
- if($proxy !== '') {
+ if ($proxy !== '') {
$settings['proxy'] = $proxy;
}
@@ -343,11 +343,11 @@ class DAV extends Common {
case 'rb':
try {
$response = $this->httpClientService
- ->newClient()
- ->get($this->createBaseUri() . $this->encodePath($path), [
- 'auth' => [$this->user, $this->password],
- 'stream' => true
- ]);
+ ->newClient()
+ ->get($this->createBaseUri() . $this->encodePath($path), [
+ 'auth' => [$this->user, $this->password],
+ 'stream' => true
+ ]);
} catch (RequestException $e) {
if ($e->getResponse() instanceof ResponseInterface
&& $e->getResponse()->getStatusCode() === 404) {
@@ -590,6 +590,15 @@ class DAV extends Common {
/** {@inheritdoc} */
public function getMimeType($path) {
+ $remoteMimetype = $this->getMimeTypeFromRemote($path);
+ if ($remoteMimetype === 'application/octet-stream') {
+ return \OC::$server->getMimeTypeDetector()->detectPath($path);
+ } else {
+ return $remoteMimetype;
+ }
+ }
+
+ public function getMimeTypeFromRemote($path) {
try {
$response = $this->propfind($path);
if ($response === false) {
@@ -606,12 +615,11 @@ class DAV extends Common {
} elseif (isset($response['{DAV:}getcontenttype'])) {
return $response['{DAV:}getcontenttype'];
} else {
- return false;
+ return 'application/octet-stream';
}
} catch (\Exception $e) {
- $this->convertException($e, $path);
+ return false;
}
- return false;
}
/**