From eae63f712531459fc0d96634f32d350e9bf82bfe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 4 Apr 2017 10:58:53 +0200 Subject: [PATCH] Add support for etag/if-none-match Signed-off-by: Joas Schilling --- README.md | 4 ++++ lib/Controller/APIController.php | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 29ee6017..8f1766c0 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,10 @@ curl -H "OCS-APIRequest: true" \ | type | string | Can be one of `link`, `settings` or `quota`; see [this issue](https://github.com/nextcloud/external/issues/7) for details | | icon | string | Full URL of the icon that should be shown next to the name of the link | +### ETag / If-None-Match + +The API provides an ETag for the sites array. In case the ETag matches the given value, a `304 Not Modified` is delivered together with an empty response body. + ### Capability The app registers a capability, so clients can check that before making the actual OCS request: diff --git a/lib/Controller/APIController.php b/lib/Controller/APIController.php index a25807a9..4f4f4d74 100644 --- a/lib/Controller/APIController.php +++ b/lib/Controller/APIController.php @@ -74,7 +74,14 @@ public function get() { $site['icon'] = $this->url->getAbsoluteURL($this->url->imagePath('external', $site['icon'])); $sites[] = $site; } - return new DataResponse($sites); + + + $etag = md5(json_encode($sites)); + if ($this->request->getHeader('If-None-Match') === $etag) { + return new DataResponse([], Http::STATUS_NOT_MODIFIED); + } + + return new DataResponse($sites, Http::STATUS_OK, ['ETag' => $etag]); } /**