Merge pull request #6682 from nextcloud/dav-mimetype-fallback
Fallback to filename based detection if the remote dav server doesn't…
This commit is contained in:
commit
e47137c7d4
|
@ -28,6 +28,7 @@
|
||||||
namespace OCA\Files_External\Tests\Storage;
|
namespace OCA\Files_External\Tests\Storage;
|
||||||
|
|
||||||
use \OC\Files\Storage\DAV;
|
use \OC\Files\Storage\DAV;
|
||||||
|
use OC\Files\Type\Detection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class WebdavTest
|
* Class WebdavTest
|
||||||
|
@ -43,7 +44,7 @@ class WebdavTest extends \Test\Files\Storage\Storage {
|
||||||
|
|
||||||
$id = $this->getUniqueID();
|
$id = $this->getUniqueID();
|
||||||
$config = include('files_external/tests/config.webdav.php');
|
$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');
|
$this->markTestSkipped('WebDAV backend not configured');
|
||||||
}
|
}
|
||||||
if (isset($config['wait'])) {
|
if (isset($config['wait'])) {
|
||||||
|
@ -61,4 +62,14 @@ class WebdavTest extends \Test\Files\Storage\Storage {
|
||||||
|
|
||||||
parent::tearDown();
|
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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ class DAV extends Common {
|
||||||
}
|
}
|
||||||
|
|
||||||
$proxy = \OC::$server->getConfig()->getSystemValue('proxy', '');
|
$proxy = \OC::$server->getConfig()->getSystemValue('proxy', '');
|
||||||
if($proxy !== '') {
|
if ($proxy !== '') {
|
||||||
$settings['proxy'] = $proxy;
|
$settings['proxy'] = $proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,6 +590,15 @@ class DAV extends Common {
|
||||||
|
|
||||||
/** {@inheritdoc} */
|
/** {@inheritdoc} */
|
||||||
public function getMimeType($path) {
|
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 {
|
try {
|
||||||
$response = $this->propfind($path);
|
$response = $this->propfind($path);
|
||||||
if ($response === false) {
|
if ($response === false) {
|
||||||
|
@ -606,13 +615,12 @@ class DAV extends Common {
|
||||||
} elseif (isset($response['{DAV:}getcontenttype'])) {
|
} elseif (isset($response['{DAV:}getcontenttype'])) {
|
||||||
return $response['{DAV:}getcontenttype'];
|
return $response['{DAV:}getcontenttype'];
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return 'application/octet-stream';
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->convertException($e, $path);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
|
|
Loading…
Reference in New Issue