diff options
author | Christopher Baines <mail@cbaines.net> | 2022-04-22 14:44:16 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2022-04-22 14:44:16 +0100 |
commit | 375532bac733f1e539c489095916be957d85a278 (patch) | |
tree | 335403cc5b4c3a056a0c39b436da87332e9c73a3 | |
parent | 35c69f37d8fc75c247831cc4a287c5b747b51d84 (diff) | |
download | nar-herder-375532bac733f1e539c489095916be957d85a278.tar nar-herder-375532bac733f1e539c489095916be957d85a278.tar.gz |
Support handling /nar requests
If the nar is known about, X-Accel-Redirect is used to pass the
request back to the webserver which should then respond with the nar.
If the nar isn't known about, then a 404 response is returned.
In either case, there's a metric incremented to record the request.
-rw-r--r-- | nar-herder/server.scm | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/nar-herder/server.scm b/nar-herder/server.scm index c977956..ea0c0a8 100644 --- a/nar-herder/server.scm +++ b/nar-herder/server.scm @@ -17,6 +17,7 @@ ;;; <http://www.gnu.org/licenses/>. (define-module (nar-herder server) + #:use-module (srfi srfi-1) #:use-module (ice-9 match) #:use-module (web uri) #:use-module (web response) @@ -145,6 +146,38 @@ (string-take narinfo 32))))) (values (build-response #:code 404) "404")))) + (('GET "nar" compression filename) + (let* ((hash (string-take filename 32)) + (narinfo-files + (database-select-narinfo-files + database + hash)) + (narinfo-file-for-compression + (find (lambda (file) + (string=? (assq-ref file 'compression) + compression)) + narinfo-files))) + + (when (or narinfo-file-for-compression + ;; Check for a common compression to avoid lots of + ;; metrics being generated if compression is random + (member compression '("gzip" "lzip" "zstd"))) + (increment-request-metric + (string-append "nar/" + compression) + (if narinfo-file-for-compression "200" "404"))) + + (if narinfo-file-for-compression + (values (build-response + #:code 200 + #:headers `((X-Accel-Redirect + . ,(string-append + "/internal/nar/" + compression "/" + filename)))) + #f) + (values (build-response #:code 404) + "404")))) (('GET "recent-changes") (let ((query-parameters (or (and=> (uri-query (request-uri request)) |