Implement correct ETag support

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-04-04 11:41:43 +02:00
Родитель ed518b1cdc
Коммит 60e4a9d403
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E166FD8976B3BAC8
6 изменённых файлов: 24 добавлений и 12 удалений

Просмотреть файл

@ -4,6 +4,7 @@
* :new: Support for icons was added with capability-entry `icons`
* :new: Support for [Rich Object Strings](https://github.com/nextcloud/server/issues/1706) was added with capability-entry `rich-strings`
* :new: ETag/If-None-Match are now evaluated and respond with `304 Not Modified` and empty body when unchanged.
## Checking the capabilities of the server
@ -93,7 +94,12 @@ The user needs to be identified/logged in by the server. Then you can just run a
}
```
**Note:** If the HTTP status code is `204` (No content), you can slow down the polling to once per hour. This status code means that there is no app that can generate notifications.
### Response codes
Status | Explanation
---|---
`204 No Content` | please slow down the polling to once per hour, since there are no apps that can generate notifications
`304 Not Modified` | The provided `If-None-Match` matches the ETag, response body is empty
### Specification

Просмотреть файл

@ -99,12 +99,9 @@ class EndpointController extends OCSController {
}
$etag = $this->generateEtag($notificationIds);
/**
* Not documented yet, check with clients
if ($this->request->getHeader('ETag') === $etag) {
return new DataResponse($data, Http::STATUS_NOT_MODIFIED);
if ($apiVersion !== 'v1' && $this->request->getHeader('If-None-Match') === $etag) {
return new DataResponse([], Http::STATUS_NOT_MODIFIED);
}
*/
return new DataResponse($data, Http::STATUS_OK, ['ETag' => $etag]);
}

Просмотреть файл

@ -93,15 +93,22 @@ class FeatureContext implements Context, SnippetAcceptingContext {
public function gettingNotifications($api, $etag) {
$headers = [];
if ($etag === ' with different etag') {
$headers['ETag'] = md5($this->lastEtag);
$headers['If-None-Match'] = substr($this->lastEtag, 0, 16);
} else if ($etag === ' with matching etag') {
$headers['ETag'] = $this->lastEtag;
$headers['If-None-Match'] = $this->lastEtag;
}
$this->sendingToWith('GET', '/apps/notifications/api/' . $api . '/notifications?format=json', null, $headers);
$this->lastEtag = $this->response->getHeader('ETag');
}
/**
* @Then /^response body is empty$/
*/
public function checkResponseBodyIsEmpty() {
PHPUnit_Framework_Assert::assertSame('', $this->response->getBody()->getContents());
}
/**
* @Then /^list of notifications has (\d+) entries$/
*

Просмотреть файл

@ -41,5 +41,7 @@ Feature: statuscodes
Then status code is 200
And list of notifications has 3 entries
When getting notifications on v1 with matching etag
Then status code is 200
# Then status code is 304 - Disabled because it's not listed in the API specs
Then status code is 200
# And response body is empty - Disabled because it's not listed in the API specs
And list of notifications has 3 entries

Просмотреть файл

@ -41,5 +41,5 @@ Feature: statuscodes
Then status code is 200
And list of notifications has 3 entries
When getting notifications on v2 with matching etag
Then status code is 200
# Then status code is 304 - Disabled because it's not listed in the API specs
Then status code is 304
And response body is empty

Просмотреть файл

@ -18,7 +18,7 @@ ${ROOT_DIR}/occ app:list | grep notifications
${ROOT_DIR}/occ app:list | grep provisioning_api
export TEST_SERVER_URL="http://localhost:8080/"
${APP_INTEGRATION_DIR}/vendor/bin/behat -f junit -f pretty
${APP_INTEGRATION_DIR}/vendor/bin/behat -f junit -f pretty $1 $2
RESULT=$?
kill $PHPPID