summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-03-07 10:03:00 +0100
committerGitHub <noreply@github.com>2018-03-07 10:03:00 +0100
commit3156d95e14049ea5490fe50fa39db95e23ff9f9e (patch)
tree63c9203cdf1bcd355f8232930f7f2f569c00266a /core
parent65cc155a1168ef0307d4d6bbe593611c34d1b89b (diff)
parent16ac8eaac9779f9ab297ab99fa5211e37563002c (diff)
downloadnextcloud-server-3156d95e14049ea5490fe50fa39db95e23ff9f9e.tar.gz
nextcloud-server-3156d95e14049ea5490fe50fa39db95e23ff9f9e.zip
Merge pull request #8652 from nextcloud/navigation-controller-etag
Add ETag to NavigationController
Diffstat (limited to 'core')
-rw-r--r--core/Controller/NavigationController.php33
1 files changed, 31 insertions, 2 deletions
diff --git a/core/Controller/NavigationController.php b/core/Controller/NavigationController.php
index 3521fac3b46..2397fb3c7b4 100644
--- a/core/Controller/NavigationController.php
+++ b/core/Controller/NavigationController.php
@@ -22,6 +22,7 @@
*/
namespace OC\Core\Controller;
+use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\INavigationManager;
@@ -54,7 +55,14 @@ class NavigationController extends OCSController {
if ($absolute) {
$navigation = $this->rewriteToAbsoluteUrls($navigation);
}
- return new DataResponse($navigation);
+
+ $etag = $this->generateETag($navigation);
+ if ($this->request->getHeader('If-None-Match') === $etag) {
+ return new DataResponse([], Http::STATUS_NOT_MODIFIED);
+ }
+ $response = new DataResponse($navigation);
+ $response->setETag($etag);
+ return $response;
}
/**
@@ -69,7 +77,28 @@ class NavigationController extends OCSController {
if ($absolute) {
$navigation = $this->rewriteToAbsoluteUrls($navigation);
}
- return new DataResponse($navigation);
+ $etag = $this->generateETag($navigation);
+ if ($this->request->getHeader('If-None-Match') === $etag) {
+ return new DataResponse([], Http::STATUS_NOT_MODIFIED);
+ }
+ $response = new DataResponse($navigation);
+ $response->setETag($etag);
+ return $response;
+ }
+
+ /**
+ * Generate an ETag for a list of navigation entries
+ *
+ * @param array $navigation
+ * @return string
+ */
+ private function generateETag(array $navigation): string {
+ foreach ($navigation as &$nav) {
+ if ($nav['id'] === 'logout') {
+ $nav['href'] = 'logout';
+ }
+ }
+ return md5(json_encode($navigation));
}
/**