diff options
author | Christopher Baines <mail@cbaines.net> | 2023-05-03 11:58:39 +0200 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-05-03 11:58:39 +0200 |
commit | afd757537d36ef0bd21ba4744879687c0d6a49c8 (patch) | |
tree | d1ded92aef4dc8e97cfedf1d31df539ea56ff3b5 | |
parent | 935ef75d590c030fbec9d3f56091b07f3bf4880b (diff) | |
download | nar-herder-afd757537d36ef0bd21ba4744879687c0d6a49c8.tar nar-herder-afd757537d36ef0bd21ba4744879687c0d6a49c8.tar.gz |
Add HEAD request support for /file/
-rw-r--r-- | nar-herder/server.scm | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/nar-herder/server.scm b/nar-herder/server.scm index 50bc70f..5634fbe 100644 --- a/nar-herder/server.scm +++ b/nar-herder/server.scm @@ -355,10 +355,12 @@ #f) (values (build-response #:code 404) "404")))))) - (('GET "file" name algo hash) + (((or 'HEAD 'GET) "file" name algo hash) (guard (c ((invalid-base32-character? c) (values (build-response #:code 404) - "404"))) + (if (eq? (request-method request) 'HEAD) + #f + "404")))) (let ((hash-bytevector (nix-base32-string->bytevector hash))) (if (and (string=? algo "sha256") (= 32 (bytevector-length hash-bytevector))) @@ -396,20 +398,26 @@ (values `((content-type . (application/octet-stream (charset . "ISO-8859-1"))) (content-length . ,bytes)) - (lambda (output-port) - (dump-port nar-port - output-port - bytes) + (if (eq? (request-method request) 'HEAD) + #f + (lambda (output-port) + (dump-port nar-port + output-port + bytes) - (close-port output-port)))))) + (close-port output-port))))))) (values (build-response #:code 404) - "404"))) + (if (eq? (request-method request) 'HEAD) + #f + "404")))) (begin (increment-request-metric "file" "404") (values (build-response #:code 404) - "404")))))) + (if (eq? (request-method request) 'HEAD) + #f + "404"))))))) (('GET "recent-changes") (let ((query-parameters |