Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions apps/dav/lib/Paginate/PaginatePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ public function onMethod(RequestInterface $request, ResponseInterface $response)

$items = $this->cache->get($url, $token, $offset, $count, $context);

$response->setStatus(207);
$response->addHeader(self::PAGINATE_HEADER, 'true');
$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
$response->setHeader('Vary', 'Brief,Prefer');

// as we cached strings of XML, rebuild the multistatus response
// and output the RAW entries, as stored in the cache
$writer = $this->server->xml->getWriter();
Expand All @@ -157,11 +152,19 @@ public function onMethod(RequestInterface $request, ResponseInterface $response)
$writer->startDocument();
$writer->startElement('{DAV:}multistatus');
foreach ($items as $item) {
if ($item === null) {
return;
}
$writer->writeRaw($item);
}
$writer->endElement();
$writer->endDocument();

$response->setStatus(207);
$response->addHeader(self::PAGINATE_HEADER, 'true');
$response->setHeader('Content-Type', 'application/xml; charset=utf-8');
$response->setHeader('Vary', 'Brief,Prefer');

$response->setBody($writer->flush());

return false;
Expand Down
27 changes: 27 additions & 0 deletions apps/dav/tests/unit/Paginate/PaginatePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,33 @@ public function testOnMethodPassesMinimalPreferenceInContext(): void {
$this->plugin->onMethod($this->request, $this->response);
}

public function testOnMethodIgnoresEvictedCacheEntries(): void {
$this->initializePlugin();

$this->request->method('hasHeader')->willReturn(true);
$this->request->method('getUrl')->willReturn('url');
$this->request->method('getHeader')->willReturnMap([
[PaginatePlugin::PAGINATE_TOKEN_HEADER, 'token'],
[PaginatePlugin::PAGINATE_OFFSET_HEADER, '0'],
[PaginatePlugin::PAGINATE_COUNT_HEADER, '2'],
]);

$this->cache->method('exists')->willReturn(true);
$this->cache->method('get')->willReturn((function (): \Generator {
yield $this->getResponseXmlForFile('/file1', 'File 1');
yield null;
})());

$this->response->expects(self::never())
->method('setStatus');
$this->response->expects(self::never())
->method('addHeader');
$this->response->expects(self::never())
->method('setBody');

self::assertNull($this->plugin->onMethod($this->request, $this->response));
}

public function testOnMultiStatusNoPaginateHeaderShouldSucceed(): void {
$this->initializePlugin();

Expand Down