Skip to content

Commit 7b716e8

Browse files
committed
Support conditional requests
1 parent de38c3c commit 7b716e8

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Dialog change log
55

66
## 3.0.0 / ????-??-??
77

8+
* Implemented support for conditional requests in Atom feed using the
9+
`If-Modified-Since` header.
10+
(@thekid)
811
* Merged PR #68: Show preview images instead of marker icons on map
912
(@thekid)
1013
* Merged PR #67: Switch journeys to display entries oldest - newest

src/main/php/de/thekid/dialog/web/Feed.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php namespace de\thekid\dialog\web;
22

33
use de\thekid\dialog\{Repository, Pagination};
4-
use web\frontend\{Handler, Get, Param, View};
4+
use util\Date;
5+
use web\Headers;
6+
use web\frontend\{Handler, Header, Get, Param, View};
57

68
#[Handler('/feed')]
79
class Feed {
@@ -15,10 +17,18 @@ public function listing(#[Param] $page= 1) {
1517
}
1618

1719
#[Get('/atom')]
18-
public function atom() {
19-
return View::named('atom')
20+
public function atom(#[Header('If-Modified-Since')] $since= null) {
21+
$items= $this->repository->newest(20);
22+
if ($since && $items && !$items[0]['date']->isAfter(new Date($since))) {
23+
$view= View::empty()->status(304);
24+
} else {
25+
$view= View::named('atom')->with(['items' => $items]);
26+
}
27+
28+
return $view
29+
->header('Cache-Control', 'max-age=3600')
2030
->header('Content-Type', 'application/atom+xml; charset=utf-8')
21-
->with(['items' => $this->repository->newest(20)])
31+
->header('Last-Modified', Headers::date($items[0]['date'] ?? null))
2232
;
2333
}
2434
}

0 commit comments

Comments
 (0)