aboutsummaryrefslogtreecommitdiff
path: root/nar-herder/server.scm
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2022-01-22 17:03:04 +0000
committerChristopher Baines <mail@cbaines.net>2022-02-02 09:44:51 +0000
commitce1dac19ef1790cc371fb3acb679a6ca871e4142 (patch)
tree2c6c6494973d36fec8023f61a330380e79e32a60 /nar-herder/server.scm
parent3fdd97406d41e1d4d09d87d3e3fc31ea11f66937 (diff)
downloadnar-herder-ce1dac19ef1790cc371fb3acb679a6ca871e4142.tar
nar-herder-ce1dac19ef1790cc371fb3acb679a6ca871e4142.tar.gz
Support specifying TTL's for narinfo responses
Using the same approach as guix publish.
Diffstat (limited to 'nar-herder/server.scm')
-rw-r--r--nar-herder/server.scm14
1 files changed, 11 insertions, 3 deletions
diff --git a/nar-herder/server.scm b/nar-herder/server.scm
index cab780c..8455d72 100644
--- a/nar-herder/server.scm
+++ b/nar-herder/server.scm
@@ -44,7 +44,8 @@
(("") '())
(() '()))))
-(define (make-request-handler database storage-root)
+(define* (make-request-handler database storage-root
+ #:key ttl negative-ttl)
(define (narinfo? str)
(and
(= (string-length str) 40)
@@ -65,9 +66,16 @@
database
(string-take narinfo 32))))
(if narinfo-contents
- (values '((content-type . (text/plain)))
+ (values `((content-type . (text/plain))
+ ,@(if ttl
+ `((cache-control (max-age . ,ttl)))
+ '()))
narinfo-contents)
- (values (build-response #:code 404)
+ (values (build-response #:code 404
+ #:headers (if negative-ttl
+ `((cache-control
+ (max-age . ,negative-ttl)))
+ '()))
"404"))))
(('GET (? narinfo? narinfo) "info")
(let ((narinfo-contents