From 30ee8b6f998b4b2e27da92b3adcdbc4683d3bcde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 29 Aug 2014 12:09:33 +0200 Subject: [PATCH 1/2] adding OC-ETag header --- lib/private/connector/sabre/file.php | 5 +++-- lib/private/connector/sabre/filesplugin.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php index 8f0642d794..bb68f44672 100644 --- a/lib/private/connector/sabre/file.php +++ b/lib/private/connector/sabre/file.php @@ -247,8 +247,7 @@ class File extends \OC\Connector\Sabre\Node implements \Sabre\DAV\IFile { * @throws \Sabre\DAV\Exception\NotImplemented * @throws \Sabre\DAV\Exception\ServiceUnavailable */ - private function createFileChunked($data) - { + private function createFileChunked($data) { list($path, $name) = \Sabre\HTTP\URLUtil::splitPath($this->path); $info = \OC_FileChunking::decodeName($name); @@ -305,6 +304,8 @@ class File extends \OC\Connector\Sabre\Node implements \Sabre\DAV\IFile { } } + // mark chunking complete + $_SERVER['X-CHUNKING_COMPLETE'] = true; $info = $this->fileView->getFileInfo($targetPath); return $info->getEtag(); } catch (\OCP\Files\StorageNotAvailableException $e) { diff --git a/lib/private/connector/sabre/filesplugin.php b/lib/private/connector/sabre/filesplugin.php index 9720519f4c..e03cac9c53 100644 --- a/lib/private/connector/sabre/filesplugin.php +++ b/lib/private/connector/sabre/filesplugin.php @@ -174,7 +174,24 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin { if (!is_null($fileId)) { $this->server->httpResponse->setHeader('OC-FileId', $fileId); } + $eTag = $this->getETag($node); + if (!is_null($eTag)) { + $this->server->httpResponse->setHeader('OC-ETag', $eTag); + } } } + /** + * @param \OC\Connector\Sabre\Node $node + */ + private function getETag($node) { + if (isset($_SERVER['HTTP_OC_CHUNKED'])) { + if (isset($_SERVER['X-CHUNKING_COMPLETE'])) { + return $node->getETag(); + } + return null; + } + return $node->getETag(); + } + } From 8d327c94a844804d0e7af057866e552bd5aafd17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 26 Mar 2015 10:49:26 +0100 Subject: [PATCH 2/2] adding unit tests --- lib/private/connector/sabre/filesplugin.php | 7 ++--- tests/lib/connector/sabre/filesplugin.php | 31 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/private/connector/sabre/filesplugin.php b/lib/private/connector/sabre/filesplugin.php index e03cac9c53..1b4b0674a5 100644 --- a/lib/private/connector/sabre/filesplugin.php +++ b/lib/private/connector/sabre/filesplugin.php @@ -184,11 +184,8 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin { /** * @param \OC\Connector\Sabre\Node $node */ - private function getETag($node) { - if (isset($_SERVER['HTTP_OC_CHUNKED'])) { - if (isset($_SERVER['X-CHUNKING_COMPLETE'])) { - return $node->getETag(); - } + public function getETag($node) { + if (isset($_SERVER['HTTP_OC_CHUNKED']) && !isset($_SERVER['X-CHUNKING_COMPLETE'])) { return null; } return $node->getETag(); diff --git a/tests/lib/connector/sabre/filesplugin.php b/tests/lib/connector/sabre/filesplugin.php index 54d43d66dd..e10d67a325 100644 --- a/tests/lib/connector/sabre/filesplugin.php +++ b/tests/lib/connector/sabre/filesplugin.php @@ -171,4 +171,35 @@ class FilesPlugin extends \Test\TestCase { $this->assertEquals(200, $result[self::GETETAG_PROPERTYNAME]); } + /** + * @dataProvider providesETagTestData + * @param $expectedETag + * @param $isChunked + * @param $isChunkComplete + */ + public function testETag($expectedETag, $isChunked, $isChunkComplete) { + if (!is_null($isChunked)) { + $_SERVER['HTTP_OC_CHUNKED'] = $isChunked; + } + if (!is_null($isChunkComplete)) { + $_SERVER['X-CHUNKING_COMPLETE'] = $isChunkComplete; + } + $node = $this->createTestNode('\OC\Connector\Sabre\File'); + + $etag = $this->plugin->getETag($node); + + $this->assertEquals($expectedETag, $etag); + } + + public function providesETagTestData() { + return [ + // non-chunked tests + ['"abc"', null, null], + ['"abc"', null, false], + + // chunked tests + [null, true, null], + ['"abc"', true, true], + ]; + } }