guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Mathieu Othacehe
Date: Fri, 26 Mar 2021 09:20:18 -0400 (EDT)

branch: master
commit ff3f25d28782a85841b5e604335fc1118ef93f01
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Fri Mar 26 13:57:39 2021 +0100

    http: Rename respond-gzipped-file.
    
    * src/cuirass/http (respond-gzipped-file): Rename it to ...
    (respond-compressed-file): ... this new procedure. Add support for bzip2
    compressed files.
    (url-handler): Adapt it.
---
 src/cuirass/http.scm | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index 2a5df10..f848b42 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -485,12 +485,19 @@ into a specification record and return it."
           (respond-file file-path)
           (respond-not-found file-name))))
 
-  (define (respond-gzipped-file file)
-    ;; Return FILE with 'gzip' content-encoding.
-    (respond `((content-type . (text/plain (charset . "UTF-8")))
-               (content-encoding . (gzip))
-               (content-disposition . (inline))
-               (x-raw-file . ,file))))
+  (define (respond-compressed-file file)
+    ;; Return FILE with 'gzip' or 'bzip2' content-encoding.
+    (let ((encoding
+           (cond ((string-suffix? ".gz" file)
+                  '((content-type . (text/plain (charset . "UTF-8")))
+                    (content-encoding . (gzip))))
+                 ((string-suffix? ".bz2" file)
+                  '((content-type . (application/bzip2
+                                     (charset . "ISO-8859-1")))))
+                 (else '()))))
+      (respond `(,@encoding
+                 (content-disposition . (inline))
+                 (x-raw-file . ,file)))))
 
   (define (respond-build-not-found build-id)
     (respond-json-with-error
@@ -668,7 +675,7 @@ into a specification record and return it."
      (let* ((build (and id (db-get-build id)))
             (log   (and build (assq-ref build #:log))))
        (if (and log (file-exists? log))
-           (respond-gzipped-file log)
+           (respond-compressed-file log)
            (respond-not-found (uri->string (request-uri request))))))
     (('GET "output" id)
      (let ((output (db-get-output
@@ -788,7 +795,7 @@ into a specification record and return it."
     (('GET "eval" (= string->number id) "log" "raw")
      (let ((log (and id (evaluation-log-file id))))
        (if (and log (file-exists? log))
-           (respond-gzipped-file log)
+           (respond-compressed-file log)
            (respond-not-found (uri->string (request-uri request))))))
 
     (('GET "search")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]