[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/04: publish: Advertise a short TTL for "baking" 404s.
From: |
Ludovic Courtès |
Subject: |
01/04: publish: Advertise a short TTL for "baking" 404s. |
Date: |
Thu, 11 May 2017 12:07:32 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit 24b21720f7c3a368efc32017c126e107a5d76f52
Author: Ludovic Courtès <address@hidden>
Date: Thu May 11 10:23:27 2017 +0200
publish: Advertise a short TTL for "baking" 404s.
* guix/scripts/publish.scm (not-found): Add #:phrase and #:ttl
parameters and honor them.
* tests/publish.scm ("with cache"): Check the 'cache-control' header on
of the 404 response.
---
guix/scripts/publish.scm | 15 +++++++++++----
tests/publish.scm | 7 +++++++
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm
index efaa549..8da75cb 100644
--- a/guix/scripts/publish.scm
+++ b/guix/scripts/publish.scm
@@ -300,10 +300,15 @@ References: ~a~%~a"
(canonical-sexp->string (signed-string info)))))
(format #f "~aSignature: 1;~a;~a~%" info (gethostname) signature)))
-(define (not-found request)
+(define* (not-found request
+ #:key (phrase "Resource not found")
+ ttl)
"Render 404 response for REQUEST."
- (values (build-response #:code 404)
- (string-append "Resource not found: "
+ (values (build-response #:code 404
+ #:headers (if ttl
+ `((cache-control (max-age . ,ttl)))
+ '()))
+ (string-append phrase ": "
(uri-path (request-uri request)))))
(define (render-nix-cache-info)
@@ -434,7 +439,9 @@ requested using POOL."
(file-expiration-time ttl)
#:delete-entry
delete-entry
#:cleanup-period ttl))))
- (not-found request))
+ (not-found request
+ #:phrase "We're baking it"
+ #:ttl 300)) ;should be available within 5m
(else
(not-found request)))))
diff --git a/tests/publish.scm b/tests/publish.scm
index 6238f37..268c324 100644
--- a/tests/publish.scm
+++ b/tests/publish.scm
@@ -355,6 +355,13 @@ FileSize: ~a~%"
(basename %item) ".nar"))
(response (http-get url)))
(and (= 404 (response-code response))
+
+ ;; We should get an explicitly short TTL for 404 in this case
+ ;; because it's going to become 200 shortly.
+ (match (assq-ref (response-headers response) 'cache-control)
+ ((('max-age . ttl))
+ (< ttl 3600)))
+
(wait-for-file cached)
(let* ((body (http-get-port url))
(compressed (http-get nar-url))