Replace logout href to avoid new etag on every request

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2018-03-05 16:22:18 +01:00
parent 723b8764d1
commit 11b6cc3f68
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
2 changed files with 22 additions and 7 deletions

View File

@ -56,12 +56,12 @@ class NavigationController extends OCSController {
$navigation = $this->rewriteToAbsoluteUrls($navigation);
}
$etag = md5(json_encode($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);
$response->setETag($etag);
return $response;
}
@ -77,15 +77,30 @@ class NavigationController extends OCSController {
if ($absolute) {
$navigation = $this->rewriteToAbsoluteUrls($navigation);
}
$etag = md5(json_encode($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);
$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));
}
/**
* Rewrite href attribute of navigation entries to an absolute URL
*

View File

@ -132,7 +132,7 @@ class NavigationControllerTest extends TestCase {
$this->request->expects($this->once())
->method('getHeader')
->with('If-None-Match')
->willReturn(md5(json_encode($navigation)));
->willReturn(md5(json_encode(['files'])));
$this->navigationManager->expects($this->once())
->method('getAll')
->with('link')
@ -143,11 +143,11 @@ class NavigationControllerTest extends TestCase {
}
public function testGetSettingsNavigationEtagMatch() {
$navigation = [ ['id' => 'files', 'href' => '/index.php/apps/files', 'icon' => 'icon' ] ];
$navigation = [ ['id' => 'logout', 'href' => '/index.php/apps/files', 'icon' => 'icon' ] ];
$this->request->expects($this->once())
->method('getHeader')
->with('If-None-Match')
->willReturn(md5(json_encode($navigation)));
->willReturn(md5(json_encode([ ['id' => 'logout', 'href' => 'logout', 'icon' => 'icon' ] ])));
$this->navigationManager->expects($this->once())
->method('getAll')
->with('settings')