Skip to content

Commit 214b362

Browse files
authored
Merge pull request #555 from HistoryAtState/fix/last-modified-open-api
fix: impl. 'created' and 'last-modified' for api calls
2 parents e8be5ca + 605c1e0 commit 214b362

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

modules/open.xql

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,36 @@ declare function open:frus-metadata() {
205205
</volumes>
206206
};
207207

208-
switch(request:get-parameter('xql-feed', ''))
209-
case 'latest' return open:frus-latest()
210-
case 'metadata' return open:frus-metadata()
211-
default return <error/>
208+
let $publication-config := map{ "publication-id": "frus" }
209+
let $created := app:created($publication-config, ())
210+
let $last-modified := app:last-modified($publication-config, ())
211+
let $not-modified-since := app:modified-since($last-modified, app:safe-parse-if-modified-since-header())
212+
213+
return
214+
if ($not-modified-since) then (
215+
(: if the "If-Modified-Since" header in the client request is later than the
216+
: last-modified date, then halt further processing of the templates and simply
217+
: return a 304 response. :)
218+
response:set-status-code(304),
219+
app:set-last-modified($last-modified)
220+
) else if (request:get-parameter('x-method', ()) eq 'head') then (
221+
(: When revalidating a cached resource and the "If-Modified-Since" header sent by the client indicates
222+
: the resource has changed in the meantime, it is just a head request. Do not render the page as the
223+
: response body is discarded anyway and just return status code 200. :)
224+
response:set-status-code(200),
225+
app:set-last-modified($last-modified)
226+
) else (
227+
(:
228+
: The HTML is passed in the request from the controller.
229+
: Run it through the templating system and return the result.
230+
:)
231+
(
232+
switch(request:get-parameter('xql-feed', ''))
233+
case 'latest' return open:frus-latest()
234+
case 'metadata' return open:frus-metadata()
235+
default return <error/>,
236+
(: only set last-modified if rendering was succesful :)
237+
app:set-last-modified($last-modified),
238+
app:set-created($created)
239+
)
240+
)

0 commit comments

Comments
 (0)